home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / bcpp / classlib / classlib.doc next >
Text File  |  1992-02-14  |  263KB  |  6,845 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. Online document
  14. ___________________________________________________________________________
  15.  
  16.  
  17.  
  18.                                               The container class libraries
  19.  
  20.  
  21.           For more  Turbo C++ version 3.0 includes two complete container
  22.  information about  class libraries: an enhanced version of the Object-
  23.     templates, see  based library supplied with version 1.0, plus a brand-
  24.   Chapter 13, "C++  new implementation based on templates. This chapter
  25.        specifics."  describes both libraries. We assume that you are
  26.                     familiar with the syntax and semantics of C++ and with
  27.                     the basic concepts of object-oriented programming
  28.                     (OOP). To understand the template-based version (called
  29.                     BIDS, for Borland International Data Structures), you
  30.                     should be acquainted with C++'s new template mechanism.
  31.  
  32.                     The chapter is divided into seven parts:
  33.  
  34.                     o A review of the difference between versions 1.0 and
  35.                       3.0 of the class libraries
  36.                     o An overview of the Object- and template-based
  37.                       libraries
  38.                     o A survey of the Object container classes, introducing
  39.                       the basic concepts and terminology
  40.                     o An overview of the BIDS library
  41.                     o The CLASSLIB directory and how to use it
  42.                     o Debugging tools
  43.                     o An alphabetic reference guide to the Object container
  44.                       library, listing each class and its members
  45.  
  46.  
  47.  
  48. ===========================================================================
  49. What's new since version 1.0?
  50. ===========================================================================
  51.  
  52.                     The version 1.0 container library is an Object-based
  53.                     implementation. Both container objects and the elements
  54.                     stored in them are all ultimately derived from the
  55.  
  56.  
  57.  
  58.                                    - 1 -
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.                     class Object. Further, the data structures used to
  66.                     implement each container class were fixed and (usually)
  67.                     hidden from the programmer. This provides a simple,
  68.                     effective model for most container applications.
  69.                     Version 3.0 therefore offers an enhanced, code-
  70.                     compatible version of the previous Object-based
  71.                     container library. We call this the Object container
  72.                     class library. In addition, a more flexible (but more
  73.                     complex), template-based container library, called BIDS
  74.                     (Borland International Data Structures), is supplied
  75.                     with version 3.0. Through the power of templates, BIDS
  76.                     lets you vary the underpinning data structure for a
  77.                     container and lets you store arbitrary objects in a
  78.                     container. With the appropriate template parameters,
  79.                     BIDS can actually emulate the Object container library.
  80.  
  81.                     Before we review the differences between the Object and
  82.                     BIDS models, we'll list the changes to the Object
  83.                     container library since version 1.0:
  84.  
  85.                     o New Btree and PriorityQueue classes.
  86.                     o New TShouldDelete class gives the programmer control
  87.                       over container/element ownership. You can control the
  88.                       fate of objects when they are detached from a
  89.                       container and when the container is flushed (using
  90.                       the new flush method) or destroyed.
  91.                     o New memory management classes, MemBlocks and
  92.                       MemStack, for efficient memory block and memory stack
  93.                       (mark-and-release) allocations.
  94.                     o New PRECONDITION and CHECK macros provide sophisti-
  95.                       cated assert mechanisms to speed application develop-
  96.                       ment and debugging.
  97.                     o New Timer class gives you a stopwatch for timing
  98.                       program execution.
  99.  
  100.    When you choose  Existing Turbo C++ version 1.01 container class code
  101.    Container Class  will still run with the version 3.0 libraries. The new
  102.     Library in the  Object container class libraries, in directory
  103.     IDE's Options|  \CLASSLIB, are distinguished by the prefix TC:
  104.   Linker|Libraries  TCLASSx.LIB and TCLASDBx.LIB where x specifies the
  105.    dialog box, the  memory model, and DB indicates the special debug
  106.       Object-based  version. To reduce verbiage, we will often refer to
  107.  libraries will be  this container implementation as the Object or TC
  108.      automatically  version.
  109.         linked in.
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.                                    - 2 -
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.         To use the  The corresponding libraries for the new template-based
  124.     template-based  container classes are distinguished by the prefix BIDS:
  125.     libraries, you  BIDSx.LIB and BIDSDBx.LIB. Let's review the reasons for
  126.    must explicitly  having two sets of container libraries. The use of all
  127.            add the  these libraries is covered on page 31.
  128.        appropriate
  129.      BIDS[DB]x.LIB
  130.    library to your
  131.         project or
  132.          makefile.
  133.  
  134.  
  135.  
  136. ===========================================================================
  137. Why two sets of libraries?
  138. ===========================================================================
  139.  
  140.                     The Object container classes have been retained and
  141.                     enhanced to provide code compatibility with the version
  142.                     1.0 library. They provide a gentler learning curve than
  143.                     the template-based BIDS library. The Object container
  144.                     code offers faster compilation but slightly slower
  145.                     execution than the template version. The project files
  146.                     for the example and demo programs are set up to use the
  147.                     Object version of the container libraries.
  148.  
  149.                     BIDS exploits the new exciting templates feature of C++
  150.                     2.1. It offers you considerable flexibility in choosing
  151.                     the best underlying data structure for a given
  152.                     container application. With the Object version, each
  153.                     container is implemented with a fixed data structure,
  154.                     chosen to meet the space/speed requirements of most
  155.                     container applications. For example, a Bag object is
  156.                     implemented with a hash table, and a Deque object with
  157.                     a double list. With BIDS you can fine-tune your
  158.                     application by varying the container implementation
  159.                     with the minimum recoding--often a single typedef will
  160.                     suffice. You can switch easily from StackAsList to
  161.                     StackAsVector and test the results. In fact, you'll see
  162.                     that by setting appropriate values for <T>, a generic
  163.                     class parameter, you can implement the Object model
  164.                     exactly. With BIDS, you can even choose between
  165.                     polymorphic and non-polymorphic implementations of the
  166.                     Object container model. Such choices between execution
  167.                     speed (non-polymorphic) and future flexibility
  168.                     (polymorphic) can be tested without major recoding.
  169.  
  170.  
  171.  
  172.  
  173.  
  174.                                    - 3 -
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.      Existing code  Both the Object and BIDS versions provide the same
  182.       based on the  functional interface. For example, the push and pop
  183.   Object container  member functions work the same for all Stack objects.
  184.       classes will  This makes the new template-based libraries highly
  185.    compile and run  compatible with existing code written for the Object
  186.    perfectly using  library.
  187.       the new BIDS
  188.   classes, just by  The objects stored in Object library containers must be
  189.     linking in the  derived from the class Object. To store ints, say, you
  190.        appropriate  would have to derive an Integer class from Object
  191.           library.  (you'll see how later). With BIDS you have complete
  192.                     freedom and direct control over the types of objects
  193.                     stored in a container. The stored data type is simply a
  194.                     value passed as a template parameter. For instance,
  195.                     BI_ListImp<int> gives you a list of ints.
  196.  
  197.                     Regardless of which container class model you elect to
  198.                     use, you should be familiar with container terminology,
  199.                     the Object class hierarchy, and the functionality
  200.                     provided for each container type. Although the classes
  201.                     in the BIDS library have different naming conventions
  202.                     and special template parameters, the prototypes and
  203.                     functionality of each class member are the same as
  204.                     those in the Object library.
  205.  
  206.  
  207.  
  208. ===========================================================================
  209. Container basics
  210. ===========================================================================
  211.  
  212.   If you are fully  We start by describing the Object container class
  213.      versed in the  hierarchy as enhanced for Turbo C++ version 3.0. This
  214.      Turbo C++ 1.0  hierarchy offers a high degree of modularity through
  215.     version of the  inheritance and polymorphism. You can use these classes
  216. container library,  as they are, or you can extend and expand them to pro-
  217.   you should first  duce an object-oriented software package specific to
  218.      check out the  your needs.
  219.     Object library
  220.       enhancements  At the top of the class hierarchy is the Object class
  221.   before moving to  (see Figure 1), an abstract class that cannot be
  222.      the templates  instantiated (no objects of its type can be declared).
  223.    section on page  An abstract class serves as an umbrella for related
  224.                14.  classes. As such, it has few if any data members, and
  225.                     some or all of its member functions are pure virtual
  226.                     functions. Pure virtual functions serve as placeholders
  227.                     for functions of the same name and signature intended
  228.  
  229.  
  230.  
  231.  
  232.                                    - 4 -
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.                     to be defined eventually in derived classes. In fact,
  240.                     any class with at least one pure virtual function is,
  241.                     by definition, an abstract class.
  242.  
  243. Figure 1: Class hierarchies in CLASSLIB
  244.  
  245. Object─┬─Error
  246.        ├─Sortable────┬─String
  247.        │             ├─BaseDate─────Date
  248.        │             └─BaseTime─────Time
  249.        ├─Association
  250.        └─Container───┬─Collection─┬─AbstractArray─┬─Array
  251.                      │            │               └─SortedArray
  252.                      │            ├─HashTable
  253.                      │            ├─Bag──Set──Dictionary
  254.                      │            ├─List
  255.                      │            ├─Btree
  256.                      │            └─DoubleList
  257.                      ├─Stack
  258.                      ├─Deque──Queue
  259.                      └─PriorityQueue
  260. ContainerIterator────┬─HashTableIterator
  261.                      ├─ListIterator
  262.                      ├─DoubleListIterator
  263.                      ├─BtreeIterator
  264.                      └─ArrayIterator
  265. Memblocks
  266. MemStack
  267.                     Note that TShouldDelete provides a second base
  268.                     (multiple inheritance) for both Container and
  269.                     Association.
  270.  
  271.                     A class derived from an abstract class can provide a
  272.                     body defining the inherited pure virtual function. If
  273.                     it doesn't, the derived class remains abstract,
  274.                     providing a base for further derivations. When you
  275.                     reach a derived class with no pure virtual functions,
  276.                     the class is called a non-abstract or instance class.
  277.                     As the name implies, instance classes can be
  278.                     instantiated to provide usable objects.
  279.  
  280.                     An abstract class can be the base for both abstract and
  281.                     instance classes. For example, you'll see that
  282.                     Container, an abstract class derived from the abstract
  283.                     class Object, is the base for both Collection
  284.                     (abstract) and Stack (instance).
  285.  
  286.  
  287.  
  288.  
  289.  
  290.                                    - 5 -
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.    To enhance your  As you read this chapter, bear in mind that a derived
  298.   understanding of  class inherits and can access all non-private data
  299.   the classes, you  members and member functions from all its ancestral
  300.   can review their  base classes. For example, the Array class does not
  301.    declarations in  need to explicitly define a function to print an array,
  302.    the source code  because its immediate parent class AbstractArray does
  303.       files in the  so. The Container class, an ancestor further up the
  304.           CLASSLIB  class tree, defines a different print function that can
  305.         directory.  also be used with an array, because an array is a
  306.                     container. To determine all the member functions
  307.                     available to an object, you will have to ascend the
  308.                     class hierarchy tree. Because the public interface is
  309.                     intended to be sufficient for applications, object-
  310.                     oriented programming makes a knowledge of private data
  311.                     members unnecessary; therefore, private members (with a
  312.                     few exceptions) are not documented in this chapter.
  313.  
  314.  
  315. ------------------  The Object-based hierarchy contains classes derived
  316.   Object-based and  from the class Object (together with some other utility
  317.      other classes  classes). Object provides a minimal set of members
  318. ------------------  representing what every derived object must do; these
  319.                     are described in the reference section under Object
  320.                     (page 84). Both the containers-as-objects and the
  321.                     objects they store are objects derived (ultimately)
  322.                     from Object. Later you'll see that the template-based
  323.                     containers can contain objects of any data type, not
  324.                     just those derived from Object.
  325.  
  326.   Class categories  =======================================================
  327.  
  328.                     The classes in or near the Object hierarchy can be
  329.                     divided into three groups:
  330.  
  331.                     o The non-container classes include Object itself, and
  332.                       those classes derived from Object, such as String and
  333.                       Date, which cannot store other objects.
  334.                     o The container classes (also derived from Object),
  335.                       such as Array and List, which can store objects of
  336.                       other, usually non-container, class types.
  337.                     o The helper and utility classes not derived from
  338.                       Object, such as TShouldDelete, ListIterator and
  339.                       MemStack.
  340.  
  341.                     Let's look at each category in more detail, although as
  342.                     with most OOP topics, they are closely related.
  343.  
  344.  
  345.  
  346.  
  347.  
  348.                                    - 6 -
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.      Non-container  =======================================================
  356.            classes
  357.                     The basic non-container classes provided are Object and
  358.                     its three children: Error (instance), Sortable
  359.                     (abstract), and Association (instance). Recall that the
  360.                     main purpose of these classes is to provide objects
  361.                     that can be stored as data elements in containers. To
  362.                     this end, all Object-derived classes provide a hashing
  363.                     function allowing any of their objects to be stored in
  364.                     a hash table.
  365.  
  366. ------------------  Error is not a normal class; it exists solely to define
  367.        Error class  a unique, special object called theErrorObject. A
  368. ------------------  pointer to theErrorObject carries the mnemonic
  369.  Error see page 74  NOOBJECT. NOOBJECT is rather like a null pointer, but
  370.   in the reference  serves the vital function of occupying empty slots in a
  371.           section.  container. For example, when an Array object is created
  372.                     (not to be confused with a traditional C array), each
  373.                     of its elements will initially contain NOOBJECT.
  374.  
  375. ------------------  Sortable is an abstract class from which sortable
  376.     Sortable class  classes must be derived. Some containers, known as
  377. ------------------  ordered collections, need to maintain their elements in
  378.                     a particular sequence. Collections such as SortedArray
  379.                     and PriorityQueue, for example, must have consistent
  380.                     methods for comparing the "magnitude" of objects.
  381.                     Sortable adds the pure virtual function isLessThan to
  382.                     its base, Object. Classes derived from Sortable need to
  383.                     define IsLessThan and IsEqual (inherited from Object)
  384.                     for their particular objects. Using these members, the
  385.                     relational operators <, ==, >, >=, and so on, can be
  386.                     overloaded for sortable objects. Typical sortable
  387.                     classes are String, Date, and Time, the objects of
  388.                     which are ordered in the natural way. Of course, string
  389.                     ordering may depend on your locale, but you can always
  390.                     override the comparison functions (another plus for
  391.                     C++).
  392.  
  393.   For more details  Distinguish between the container object and the
  394.    on Sortable see  objects it contains: Sortable is the base for non-
  395.     page 93 in the  container objects; it is not a base for ordered
  396. reference section.  collections. Every class derived from Object inherits
  397.                     the isSortable member function so that objects can be
  398.                     queried as to their "sortability."
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.                                    - 7 -
  407.  
  408.  
  409.  
  410.  
  411.  
  412.  
  413. ------------------  Association is a non-container, instance class
  414.  Association class  providing special objects to be stored (typically) in
  415. ------------------  Dictionary collections. An Association object, known as
  416.    Association see  an association, is a pair of objects known as the key
  417.     page 44 in the  and the value. The key (which is unique in the
  418. reference section.  dictionary) can be used to retrieve the value. Every
  419.                     class derived from Object inherits the isAssociation
  420.                     member function so that objects can report whether they
  421.                     are associations or not.
  422.  
  423.  Container classes  =======================================================
  424.  
  425.                     In the Object-based library, all the container storage
  426.                     and access methods assume that the stored elements are
  427.                     derived from Object. They are actually stored as
  428.                     references or pointers to Object offering the
  429.                     advantages and disadvantages of polymorphism. Most of
  430.                     the container access member functions are virtual, so a
  431.                     container does not need to "know" how its contained
  432.                     elements were derived. A container can, in theory,
  433.                     contain mixed objects of different class types, so
  434.                     proper care is needed to maintain type-safe linkage.
  435.                     Every class has member functions called IsA and nameOf,
  436.                     which allow objects to announce their class ID and
  437.                     name. As you've seen, there are also isSortable and
  438.                     isAssociation member functions for testing object
  439.                     types.
  440.  
  441.                     All the container classes are derived from the abstract
  442.                     Container class, a child of Object. Container
  443.                     encapsulates just a few simple properties upon which
  444.                     more specialized containers can be built. The basic
  445.                     container provides the following functionality:
  446.  
  447.                     o Displays its elements
  448.                     o Calculates its hash value
  449.                     o Pure virtual slot for counting the number of items
  450.                       with getItemsInContainer
  451.                     o Pure virtual slot for flushing (emptying) the
  452.                       container with flush
  453.                     o Performs iterations over its elements
  454.                     o Reports and changes the ownership of its elements
  455.                       (inherited from TShouldDelete)
  456.  
  457.                     So far, our containers have no store, access, or detach
  458.                     methods. (We can flush the container but we cannot
  459.                     detach individual elements.) Nor is there a hasMember
  460.  
  461.  
  462.  
  463.  
  464.                                    - 8 -
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.                     member function, that is, a general way of determining
  472.                     whether a given object is an element of the container.
  473.                     This is a deliberate design decision. As we move up the
  474.                     hierarchy, you'll see that what distinguishes the
  475.                     various derived container classes are the storage and
  476.                     access rules that actually define each container's
  477.                     underlying data structure. Thus push and pop member
  478.                     functions are added for Stack, indexing operators are
  479.                     added for Array, and so on. There is not enough in
  480.                     common to warrant having generic add and retrieve
  481.                     methods at the Container level. There is no one perfect
  482.                     way of extracting common properties from groups of
  483.                     containers, and therefore no perfect container class
  484.                     hierarchy. The Object-based container hierarchy is just
  485.                     one possible design based on reasonable compromises.
  486.                     The BIDS version, as you'll see, offers a different
  487.                     perspective.
  488.  
  489.                     The first three Container functions listed previously
  490.                     are fairly self-explanatory. We'll discuss the
  491.                     important subjects of ownership and iteration in the
  492.                     next two sections.
  493.  
  494.  
  495.     Containers and  =======================================================
  496.          ownership
  497.                     Before you use the Container family, you must
  498.                     understand the concept of ownership. As in real life, a
  499.                     C++ container starts out empty and must be filled with
  500.                     objects before the objects can be said to be in the
  501.                     container. Unlike the real world, however, when objects
  502.                     are placed in the container, they are, by default,
  503.                     owned by the container. The basic idea is that when a
  504.                     container owns its objects, the objects are destroyed
  505.                     when the container is destroyed.
  506.  
  507.                     Recall that containers are themselves objects subject
  508.                     to the usual C++ scoping rules, so local containers
  509.                     come and go as they move in and out of scope. Care is
  510.                     needed, therefore, to prevent unwanted destruction of a
  511.                     container's contents, so provision is made for changing
  512.                     ownership. A container can, throughout its lifetime,
  513.                     relinquish and regain ownership of its objects as often
  514.                     as it likes by calling the ownsElements member function
  515.                     (inherited from TShouldDelete). The fate of its objects
  516.                     when the container disappears is determined by the
  517.                     ownership status ruling at the time of death. Consider
  518.                     the following:
  519.  
  520.  
  521.  
  522.                                    - 9 -
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.                      void test()
  530.                      {
  531.                        Array a1( 10 );    // construct an array
  532.                        Array a2( 10 );    // and another
  533.  
  534.                        a1.ownsElements( 1 );  // array a1 owns its objects
  535.                                                  (the default)
  536.                        a2.ownsElements( 0 );  // array a2 relinquishes
  537.                                                  ownership
  538.  
  539.                        // load and manipulate the arrays here
  540.  
  541.                      }
  542.  
  543.                     When test exits, a1 will destroy its objects, but the
  544.                     objects in a2 will survive (subject, of course, to
  545.                     their own scope). The a1.ownsElements( 1 ) call is not
  546.                     really needed since, by default, containers own their
  547.                     contents.
  548.  
  549.                     Ownership also plays a role when an object is removed
  550.                     from a container. The pure virtual function
  551.                     Container::flush is declared as
  552.  
  553.                        virtual void flush( DeleteType dt = DefDelete ) = 0;
  554.  
  555.                     flush empties the container but whether the flushed
  556.                     objects are destroyed or not is controlled by the dt
  557.                     argument. DeleteType is an enum defined in
  558.                     TShouldDelete. A value of NoDelete means preserve the
  559.                     flushed objects regardless of ownership; Delete means
  560.                     destroy the objects regardless of ownership; DefDelete,
  561.                     the default value, means destroy the objects only if
  562.                     owned by the container. Similarly Collection (derived
  563.                     from Container) has a detach member function, declared
  564.                     as
  565.  
  566.                        virtual void detach( Object& obj, DeleteType dt =
  567.                        NoDelete ) = 0;
  568.  
  569.                     which looks for obj in the collection and removes it if
  570.                     found. Again, the fate of the detached object is
  571.                     determined by the value dt. Here, the default is not to
  572.                     destroy the detached object. Collection::destroy is a
  573.                     variant that calls detach with DefDelete.
  574.  
  575.                     A related problem occurs if you destroy an object that
  576.                     resides in a container without "notifying" the
  577.  
  578.  
  579.  
  580.                                   - 10 -
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.                     container. The safest approach is to use the
  588.                     container's methods to detach and destroy its contents.
  589.  
  590.         Important!  If you declare an automatic object (an object that's
  591.                     local to your routine) and place that object in a
  592.                     global container, your local object will be destroyed
  593.                     when the routine leaves the scope in which it was
  594.                     declared. To prevent this, you must only add heap
  595.                     objects (objects that aren't local to the current
  596.                     scope) to global containers. Similarly, when you remove
  597.                     an object from a global container, you are responsible
  598.                     for destroying it and freeing the space in which it
  599.                     resides.
  600.  
  601.  
  602.          Container  =======================================================
  603.          iterators
  604.                     You saw earlier that Container, the base for all
  605.                     containers in the Object-based library, supports
  606.                     iteration. Iteration means traversing or scanning a
  607.                     container, accessing each stored object in turn to
  608.                     perform some test or action. The separate
  609.                     ContainerIterator-based hierarchy provides this
  610.                     functionality. Iterator classes are derived from this
  611.                     base to provide iterators for particular groups of
  612.                     containers, so you'll find HashTableIterator,
  613.                     ListIterator, BtreeIterator, and so on.
  614.  
  615.              Under  There are two flavors of iterators: internal and
  616.  ContainerIterator  external. Each container inherits the three member
  617.  on page 64 in the  functions: firstThat, lastThat, and forEach, via the
  618. reference section,  Object and Container classes. As the names indicate,
  619.    you see how the  these let you scan through a container either testing
  620.     pre- and post-  each element for a condition or performing an action on
  621.          increment  each of the container's elements. When you invoke one
  622.   operators ++ are  of these three member functions, the appropriate
  623.      overloaded to  iterator object is created for you internally to
  624.      simplify your  support the iteration. Most iterations can be performed
  625. iterator programs.  in this way since the three iterating functions are
  626.                     very flexible. They take a pointer-to-function argument
  627.                     together with an arbitrary parameter list, so you can
  628.                     do almost anything. For even more flexibility, there
  629.                     are external iterators that you can build via the
  630.                     initIterator member function. With these, you have to
  631.                     set up your own loops and test for the end-of-
  632.                     container.
  633.  
  634.  
  635.  
  636.  
  637.  
  638.                                   - 11 -
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.                     Returning to the container class hierarchy, we look at
  646.                     three classes derived directly from Container: Stack,
  647.                     Deque, and PriorityQueue.
  648.  
  649.  
  650.   Sequence classes  =======================================================
  651.  
  652.                     The instance classes Stack, Deque (and its offspring
  653.                     Queue), and PriorityQueue are containers collectively
  654.                     known as sequence classes. A sequence class is
  655.                     characterized by the following properties:
  656.  
  657.                     1. Objects can be inserted and removed.
  658.  
  659.                     2. The order of insertions and deletions is
  660.                        significant.
  661.  
  662.                     3. Insertions and extractions can occur only at
  663.                        specific points, as defined by the individual class.
  664.                        In other words, access is nonrandom and restricted.
  665.  
  666.                     Sequences (like all containers) know how many elements
  667.                     they have (using getItemsInContainer) and if they are
  668.                     empty or not (using isEmpty). However, they cannot
  669.                     usually determine if a given object is a member or not
  670.                     (there is still no general hasMember or findMember
  671.                     member function). Stacks, queues, priority queues, and
  672.                     deques vary in their access methods as explained in
  673.                     more detail in the reference section.
  674.  
  675.                     Sequence is not itself a class because sequences do not
  676.                     share enough in common to warrant a separate base
  677.                     class. However, you might find it helpful to consider
  678.                     the classes together when reviewing the container
  679.                     hierarchy.
  680.  
  681.  
  682.        Collections  =======================================================
  683.  
  684.                     The next level of specialization is the abstract class
  685.                     Collection, derived from Container, and poised to
  686.                     provide a slew of widely used data structures. The key
  687.                     difference between collections and containers  is that
  688.                     we now have general hasMember and findMember member
  689.                     functions.
  690.  
  691.                     From Collection we derive the unordered collections
  692.                     Bag, HashTable, List, DoubleList, and AbstractArray,
  693.  
  694.  
  695.  
  696.                                   - 12 -
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.                     and the ordered collection Btree. In turn,
  704.                     AbstractArray spawns the unordered Array and the
  705.                     ordered SortedArray. Bag serves as the base for Set
  706.                     which in turn is the base for Dictionary. These
  707.                     collections all refine the storage and retrieval
  708.                     methods in their own fashions.
  709.  
  710.  
  711. ------------------  With unordered collections, any objects derived from
  712.          Unordered  Object can be stored, retrieved, and detached. The
  713.        collections  objects do not have to be sortable because the access
  714. ------------------  methods do not depend on the relative "magnitude" of
  715.                     the elements. Classes that fall into this category are
  716.  
  717.                     o HashTable
  718.                     o Bag, Set, and Dictionary
  719.                     o List and DoubleList
  720.                     o Array
  721.  
  722.  
  723. ------------------  An ordered collection depends on relative "magnitude"
  724.            Ordered  when adding or retrieving its elements. Hence these
  725.        collections  elements must be objects for which the isLessThan
  726. ------------------  member function is defined. In other words, the
  727.                     elements in an ordered collection must be derived from
  728.                     the class Sortable. The following are ordered
  729.                     collections:
  730.  
  731.                     o Btree
  732.                     o SortedArray
  733.  
  734.  
  735.  
  736. ===========================================================================
  737. The BIDS template library
  738. ===========================================================================
  739.  
  740.                     The BIDS container class library can be used as a
  741.                     springboard for creating useful classes for your
  742.                     individual needs. Unlike the Object container library,
  743.                     BIDS lets you fine-tune your applications by varying
  744.                     the underlying data structures for different containers
  745.                     with minimum reprogramming. This extends the power of
  746.                     encapsulation: the implementor can change the internals
  747.                     of a class with little recoding and the user can easily
  748.                     replace a class with one that provides a more
  749.                     appropriate algorithm. The BIDS class library achieves
  750.                     this flexibility by using the C++ template mechanism.
  751.  
  752.  
  753.  
  754.                                   - 13 -
  755.  
  756.  
  757.  
  758.  
  759.  
  760.  
  761.        For a basic  With BIDS, the container is considered as an ADT
  762. description of C++  (abstract data type), and its underlying data structure
  763.      templates see  is independently treated as an FDS (fundamental data
  764.        Chapter 13.  structure). BIDS also allows separate selections of the
  765.                     type of objects to be stored, and whether to store the
  766.                     objects themselves or pointers to objects.
  767.  
  768.         Templates,  =======================================================
  769.       classes, and
  770.         containers  Computer science has devoted much attention to devising
  771.                     suitable data structures for different applications.
  772.                     Recall Wirth's equation, Programs = Algorithms + Data
  773.                     Structures, which stresses the equal importance of data
  774.                     structures and their access methods.
  775.  
  776.                     As used in current OOP terminology, a container is
  777.                     simply an object that implements a particular data
  778.                     structure, offering member functions for adding and
  779.                     accessing its data elements (usually other objects)
  780.                     while hiding from the user as much of the inner detail
  781.                     as possible. There are no simple rules to determine the
  782.                     best data structure for a given program. Often, the
  783.                     choice is a compromise between competing space (RAM)
  784.                     and time (accessibility) considerations, and even here
  785.                     the balance can shift suddenly if the number of
  786.                     elements or the frequency of access grows or falls
  787.                     beyond a certain number.
  788.  
  789.  
  790.          Container  =======================================================
  791.     implementation
  792.                     Often, you can implement the desired container
  793.                     properties in many ways using different underlying data
  794.                     structures. For example, a stack, characterized by its
  795.                     Last-In-First-Out (LIFO) access, can be implemented as
  796.                     a vector, a linked list, or perhaps some other
  797.                     structure. The vector-based stack is appropriate when
  798.                     the maximum number of elements to be stored on the
  799.                     stack is known in advance. A vector allocates space for
  800.                     all its elements when it is created. The stack as a
  801.                     list is needed when there is no reasonable upper bound
  802.                     to the size of the stack. The list is a slower imple-
  803.                     mentation than the vector, but it doesn't use any more
  804.                     memory than it needs for the current state of the
  805.                     stack.
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.                                   - 14 -
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.                     The way objects are stored in the container also
  820.                     affects size and performance: they can be stored
  821.                     directly by copying the object into the data structure,
  822.                     or stored indirectly via pointers. The type of data to
  823.                     be stored is a key factor. A stack of ints, for
  824.                     example, would probably be stored directly, where large
  825.                     structs would call for indirect storage to reduce
  826.                     copying time. For "in-between" cases, however, choosing
  827.                     strategies is not always so easy. Performance tuning
  828.                     requires the comparison of different container
  829.                     implementations, yet traditionally this entails drastic
  830.                     recoding.
  831.  
  832.  
  833.       The template  =======================================================
  834.           solution
  835.                     The template approach lets you develop a stack-based
  836.                     application, say, using vectors as the underlying
  837.                     structure. You can change this to a list implementation
  838.                     without major recoding (a single typedef change, in
  839.                     fact). The BIDS library also lets you experiment with
  840.                     object-storage strategies late in the development
  841.                     cycle. Each container-data structure combination is
  842.                     implemented with both direct and indirect object
  843.                     storage, and the template approach allows a switch of
  844.                     strategy with minimal rewriting. The data type of the
  845.                     stored elements is also easy to change using template
  846.                     parameters, and you are free to use any data type you
  847.                     want.
  848.  
  849.                     As you'll see, BIDS offers container/data structure
  850.                     combinations that match those of the Object-based
  851.                     version. For example, the Object library implements
  852.                     Stack using lists, so Stack can be simulated exactly
  853.                     with the template class BI_TCStackAsList. Let's look at
  854.                     the template approach in more detail.
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.                                   - 15 -
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877. ------------------  We discussed earlier the stack and its possible
  878.      ADTs and FDSs  implementations as a linked list or as a vector. The
  879. ------------------  potential for confusion is that stacks, lists, and
  880.                     vectors are all commonly referred to as data
  881.                     structures. However, there is a difference. We can
  882.                     define a stack abstractly in terms of its LIFO
  883.                     accessibility, but it's difficult to envision a list
  884.                     without thinking of specifics such as nodes and
  885.                     pointers. Likewise, we picture a vector as a concrete
  886.                     sequence of adjacent memory locations. So we call the
  887.                     stack an ADT (abstract data type) and we call the list
  888.                     and vector FDSs (fundamental data structures). The BIDS
  889.                     container library offers each of the standard ADTs
  890.                     implemented with a choice of appropriate FDSs. Table 1
  891.                     indicates the combinations provided:
  892.  
  893.          ADTs as
  894. fundamental data    -------------------------------------------------------
  895.       structures                                      ADT              Sorted
  896.                     FDS          Stack  Queue  Deque  Bag  Set  Array  Array
  897.                     -------------------------------------------------------
  898.  
  899.                     Vector       x      x      x      x    x    x      x
  900.                     List         x
  901.                     DoubleList          x      x
  902.  
  903.                     -------------------------------------------------------
  904.  
  905.                     The abstract data types involved are Stacks, Queues,
  906.                     Deques, Bags, Sets, and Arrays. Each ADT can be
  907.                     implemented several different ways using the
  908.                     fundamental data structures Vector, List, and
  909.                     DoubleList as indicated by a bullet ( x ) in the table.
  910.                     Thus, all ADTs are implemented as vectors. In addition,
  911.                     Stacks are implemented as a list; Queues and Deques
  912.                     implemented as doubly-linked lists. (Not shown in the
  913.                     table are the sorted and counted FDSs from which
  914.                     various ADTs can be developed.)
  915.  
  916.                     There is nothing sacred about these combinations; you
  917.                     can use the template classes to develop your own
  918.                     ADT/FDS implementations.
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.                                   - 16 -
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935. ------------------  ADTs are implemented in both direct and indirect
  936.    Class templates  versions. The direct versions store the objects
  937. ------------------  themselves, while the indirect versions store pointers
  938.                     to objects. You can store whatever objects you want as
  939.                     elements in these FDSs using the power of templates.
  940.                     Here are the ADT and FDS templates we provide:
  941.  
  942.  
  943. ---------------------------------------------------------------------------
  944. Table 2: FDS class templates
  945.  
  946. Class template              Description
  947. ---------------------------------------------------------------------------
  948.  
  949. BI_VectorImp<T>             vector of Ts
  950. BI_VectorIteratorImp<T>     iterator for a vector of Ts
  951. BI_CVectorImp<T>            counted vector of Ts
  952. BI_SVectorImp<T>            sorted vector of Ts
  953. BI_IVectorImp<T>            vector of pointers to T
  954. BI_IVectorIteratorImp<T>    iterator for a vector of pointers to T
  955. BI_ICVectorImp<T>           counted vector of pointers to T
  956. BI_ISVectorImp<T>           sorted vector of pointers to T
  957. BI_ListImp<T>               list of Ts
  958. BI_SListImp<T>              sorted list of Ts
  959. BI_IListImp<T>              list of pointers to T
  960. BI_ISListImp<T>             sorted list of pointers to T
  961. BI_DoubleListImp<T>         double-linked list of Ts
  962. BI_SDoubleListImp<T>        sorted double-linked list of Ts
  963. BI_IDoubleListImp<T>        double-linked list of pointers to T
  964. BI_ISDoubleListImp<T>       sorted double-linked list of pointers to T
  965.  
  966. ---------------------------------------------------------------------------
  967.  
  968.                     Each basic FDT has a direct and indirect iterator; to
  969.                     save space we have shown only the Vector iterators.
  970.  
  971.                     The BI_ prefix stands for Borland International and the
  972.                     suffix Imp for implementation. The indirect versions
  973.                     have the prefix BI_I with the extra I for Indirect. The
  974.                     extra prefixes S and C mean Sorted and Counted
  975.                     respectively. The template parameter T in <T>
  976.                     represents the data type of the objects to be stored.
  977.                     You instantiate the template by supplying this data
  978.                     type. For example, BI_ListImp<double> gives you a list
  979.                     of doubles. See Table 3 on page 19 for a summary of
  980.                     these abbreviations. For direct object storage, the
  981.  
  982.  
  983.  
  984.  
  985.  
  986.                                   - 17 -
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.                     type T must have meaningful copy semantics and a
  994.                     default constructor. Indirect containers, however, hold
  995.                     pointers to T, and pointers always have
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.                                   - 18 -
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.                     good copy semantics. This means that indirect
  1052.                     containers can contain objects of any type.
  1053.  
  1054. Abbreviations in
  1055.   CLASSLIB names    -----------------------------------------------------------------
  1056.                     Abbreviation       Description
  1057.                     -----------------------------------------------------------------
  1058.  
  1059.                       I                Indirect
  1060.                       C                Counted
  1061.                       S                Sorted
  1062.                       O                Object-based, non-polymorphic
  1063.                       TC               Object-based, polymorphic (compatible with
  1064.                                        original Turbo C++ library)
  1065.  
  1066.                     -----------------------------------------------------------------
  1067.  
  1068.    For details see  For the sorted FDSs (BI_SVectorImp, BI_ISVectorImp, and
  1069.     the discussion  so on), T must have valid == and < operators to define
  1070.  under Sortable on  the ordering of the elements. It should be clear that
  1071.           page 94.  the IS variants refer to the objects being sorted, not
  1072.                     that the pointers to the objects are sorted.
  1073.  
  1074.                     Each implementation of an ADT with an FDS is named
  1075.                     using the convention (ADT)As(FDS)<T>, as follows:
  1076.  
  1077.  
  1078. ----------------------------------------------------------------------------
  1079. Table 4: ADT class templates
  1080.  
  1081. Class name                    Description
  1082. ----------------------------------------------------------------------------
  1083.  
  1084. BI_StackAsVector<T>           Stack of Ts as a vector
  1085. BI_QueueAsVector<T>           Queue of Ts as a vector
  1086. BI_DequeAsVector<T>           Deque of Ts as a vector
  1087. BI_BagAsVector<T>             Bag of Ts as a vector
  1088. BI_SetAsVector<T>             Set of Ts as a vector
  1089. BI_ArrayAsVector<T>           Array of Ts as a vector
  1090. BI_SArrayAsVector<T>          Sorted array of Ts as a vector
  1091.  
  1092. BI_IStackAsVector<T>          Stack of pointers to T as a vector
  1093. BI_IQueueAsVector<T>          Queue of pointers to T as a vector
  1094.  
  1095. ...                           and so on
  1096.  
  1097. BI_StackAsList<T>             Stack of Ts as a list
  1098. BI_IStackAsList<T>            Stack of pointers to T as a list
  1099.  
  1100.  
  1101.  
  1102.                                   - 19 -
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109. Table 4: ADT class templates (continued)___________________________________
  1110.  
  1111. BI_QueueAsDoubleList<T>       Queue of Ts as a double list
  1112. BI_DequeAsDoubleList<T>       Deque of Ts as a double list
  1113. BI_IQueueAsDoubleList<T>      Queue of pointers to T as a double list
  1114. BI_IDequeAsDoubleList<T>      Deque of pointers to T as a double list
  1115.  
  1116. ----------------------------------------------------------------------------
  1117.  
  1118.     There are also  Again, the <T> argument, either a class or predefined
  1119.        BI_Oxxx and  data type, provides the data type for the contained
  1120.  BI_TCxxx variants  elements. Each of the bulleted items ( x ) in Table 1
  1121.    discussed soon.  can be mapped to two templates (direct and indirect
  1122.                     versions) with names following this convention.
  1123.  
  1124.  
  1125.    Container class  ========================================================
  1126.      compatibility
  1127.                     Each template must be instantiated with a particular
  1128.                     data type as the type of the element that it will hold.
  1129.                     This allows the compiler to generate the correct code
  1130.                     for dealing with any possible type of element without
  1131.                     restricting the elements to just those derived from
  1132.                     Object.
  1133.  
  1134.                     Each ADT is also used to instantiate two classes that
  1135.                     imitate the behavior of the Object class libraries. Here
  1136.                     is a list of them:
  1137.  
  1138.  
  1139.                     --------------------------------------------------------
  1140. Object-based FDS    Class name                Description
  1141.          classes    --------------------------------------------------------
  1142.  
  1143.                     BI_OStackAsVector         Stack of pointers to Object,
  1144.                                               as a vector
  1145.                     BI_OQueueAsVector         Queue of pointers to Object,
  1146.                                               as a vector
  1147.                     BI_ODequeAsVector         Deque of pointers to Object,
  1148.                                               as a vector
  1149.                     BI_OBagAsVector           Bag of pointers to Object, as
  1150.                                               a vector
  1151.                     BI_OSetAsVector           Set of pointers to Object, as
  1152.                                               a vector
  1153.                     BI_OArrayAsVector         Array of pointers to Object,
  1154.                                               as a vector
  1155.                     BI_OSArrayAsVector        Sorted array of pointers to
  1156.                                               Object, as a vector
  1157.  
  1158.  
  1159.  
  1160.                                   - 20 -
  1161.  
  1162.  
  1163.  
  1164.  
  1165.  
  1166.  
  1167.                     Table 5: Object-based FDS classes (continued)__________
  1168.  
  1169.                     BI_TCStackAsVector        Polymorphic stack of pointers
  1170.                                               to Object, as a vector
  1171.                     BI_TCQueueAsVector        Polymorphic queue of pointers
  1172.                                               to Object, as a vector
  1173.                     BI_TCDequeAsVector        Polymorphic deque of pointers
  1174.                                               to Object, as a vector
  1175.                     BI_TCBagAsVector          Polymorphic bag of pointers to
  1176.                                               Object, as a vector
  1177.                     BI_TCSetAsVector          Polymorphic set of pointers to
  1178.                                               Object, as a vector
  1179.                     BI_TCArrayAsVector        Polymorphic array of pointers
  1180.                                               to Object, as a vector
  1181.                     BI_TCSArrayAsVector       Polymorphic sorted array of
  1182.                                               pointers to Object, as a
  1183.                                               vector
  1184.  
  1185.                     BI_OStackAsList           Stack of pointers to Object,
  1186.                                               as a list
  1187.                     BI_TCStackAsList          Polymorphic stack of pointers
  1188.                                               to Object, as a list
  1189.  
  1190.                     BI_OQueueAsDoubleList     Queue of pointers to Object,
  1191.                                               as a double list
  1192.                     BI_ODequeAsDoubleList     Deque of pointers to Object,
  1193.                                               as a double list
  1194.  
  1195.                     BI_TCQueueAsDoubleList    Polymorphic queue of pointers
  1196.                                               to Object, as a double list
  1197.                     BI_TCDequeAsDoubleList    Polymorphic deque of pointers
  1198.                                               to Object, as a double list
  1199.  
  1200.                     --------------------------------------------------------
  1201.  
  1202.                     Note that these versions have no explicit <T>
  1203.                     parameters; they use the fixed data types shown
  1204. The TCxxx versions  (pointers to Object). The BI_Oxxx (O for Object library)
  1205.     offer the same  versions of these classes have no virtual functions.
  1206.       behavior and  This makes it easier for the compiler to generate inline
  1207.  interfaces as the  function expansions, which in turn makes the BI_Oxxx
  1208.    Object library.  versions of the containers somewhat faster than the
  1209.                     corresponding polymorphic BI_TCxxx (TC for Turbo C++)
  1210.                     versions. The obverse of the coin is that the BI_Oxxx
  1211.                     versions do not share the polymorphic behavior of the
  1212.                     Object container library.
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.                                   - 21 -
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.                     In the Object container library, Stack implements a
  1226.                     stack as a polymorphic list of pointers to Object. The
  1227.                     BIDS class BI_TCStackAsList therefore mirrors the
  1228.                     Object-based class Stack. Even with BI_TCStackAsVector,
  1229.                     the public interface and semantics are the same as for
  1230.                     the Object-based Stack. The user "sees" the ADT while
  1231.                     the FDS is "hidden." For these reasons, we will not
  1232.                     repeat the alphabetic list of Object-based classes and
  1233.                     member functions for the BIDS library.
  1234.  
  1235.                     Consider your many choices when writing container code
  1236.                     with the BIDS model. You can gain speed over future
  1237.                     flexibility by using the non-polymorphic classes, such
  1238.                     as BI_OStackAsList or BI_OStackAsVector. Or you can
  1239.                     retain the polymorphism of the Object-based hierarchy by
  1240.                     using the BI_TCxxx classes.
  1241.  
  1242.  
  1243.       Header files  ========================================================
  1244.  
  1245.                     Each group of FDSs is defined in its own header file,
  1246.                     which contains templates for both the direct and the
  1247.                     indirect versions. The names of the headers are as
  1248.                     follows:
  1249.  
  1250.                       vectimp.h
  1251.                       listimp.h
  1252.                       dlistimp.h
  1253.  
  1254.                     In vectimp.h, for example, you'll find declarations for
  1255.                     all the vector, counted vector, and sorted vector
  1256.                     templates, together those for a direct and indirect
  1257.                     vector iterator.
  1258.  
  1259.                     Note also the stdtempl.h file that defines the useful
  1260.                     template functions min, max, and range. If you are new
  1261.                     to templates, this file offers a useful, gentle
  1262.                     introduction to the subject.
  1263.  
  1264.                     Each ADT family is defined in its own header file, named
  1265.                     as follows:
  1266.  
  1267.                       stacks.h
  1268.                       queues.h
  1269.                       deques.h
  1270.                       bags.h
  1271.                       sets.h
  1272.                       arrays.h
  1273.  
  1274.  
  1275.  
  1276.                                   - 22 -
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.    Note the plural  The file stacks.h, for example, defines the following
  1284.          form that  templates:
  1285.  distinguishes the
  1286. BIDS include files   BI_StackAsVector<T>
  1287.   from the Object-   BI_IStackAsVector<T>
  1288. based include file   BI_OStackAsVector
  1289.                      BI_TCStackAsVector
  1290.                      BI_StackAsList<T>
  1291.                      BI_IStackAsList<T>
  1292.                      BI_OStackAsList
  1293.                      BI_TCStackAsList
  1294.  
  1295.  
  1296.          Tuning an  ========================================================
  1297.        application
  1298.                     Consider the following example:
  1299.  
  1300.                      typedef BI_StackAsVector<int> intStack;
  1301.  
  1302.                      int main()
  1303.                      {
  1304.                        intStack is;
  1305.                        for( int i = 0; i < 10; i++ )
  1306.                          is.push( i );
  1307.                        for( i = 0; i < 10; i++ )
  1308.                          cout << is.pop() << endl;
  1309.                        return(0);
  1310.                      }
  1311.  
  1312.                     Here we are implementing a stack of ints using a vector
  1313.                     as the underlying data structure. If you later determine
  1314.                     that a list would be a more suitable implementation for
  1315.                     the stack, you can simply replace the typedef with the
  1316.                     following:
  1317.  
  1318.                         typedef BI_StackAsList<int> intStack;
  1319.  
  1320.                     After recompilation, the stack implementation is changed
  1321.                     from vector to list. Similarly, you can try a stack of
  1322.                     pointers to int, with:
  1323.  
  1324.                         typedef BI_IStackAsList<int> intStack;
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.                                   - 23 -
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341. FDS implementation  ========================================================
  1342.  
  1343.                     Each FDS is implemented as two templates, one that
  1344.                     provides the direct version, and one that provides the
  1345.                     indirect version. The indirect version makes use of an
  1346.                     InternalIxxxImp class. The following simplified extract
  1347.                     from listimp.h will give you an idea how the different
  1348.                     list FDSs are implemented. Note that BI_ListElement<T>
  1349.                     is an internal template class used to implement the node
  1350.                     (data of type T and pointer to next node) of a list. The
  1351.                     direct list of objects of type T is implemented by the
  1352.                     template class BI_ListImp<T>, which also provides the
  1353.                     base for BI_SListImp<T> (sorted lists). The example
  1354.                     shows how the add member function is implemented in the
  1355.                     direct, indirect, sorted and unsorted lists.
  1356.  
  1357.                      template <class T> class BI_ListElement
  1358.                      {
  1359.                      public:
  1360.                        BI_ListElement( T t, BI_ListElement<T> *p ) : data(t)
  1361.                          { next = p->next; p->next = this; }
  1362.                      // constructor
  1363.                      ...
  1364.                        BI_ListElement<T> *next;    // pointer to next node
  1365.                        T data;                     // object at node
  1366.                      ...
  1367.                      };
  1368.  
  1369.                      template <class T> class BI_ListImp
  1370.                      // linked list (unsorted) of type T objects; assumes T
  1371.                      has meaningful // copy semantics and a default
  1372.                      constructor
  1373.                      {
  1374.                      public:
  1375.                      ...
  1376.                        void add( T t ) { new BI_ListElement<T>( t, &head );
  1377.                      }
  1378.                      // adds objects at head of list (shown inline here to
  1379.                      save space)
  1380.                        T peekHead() const { return head.next->data; }
  1381.                      ...
  1382.                      };
  1383.  
  1384.                      template <class T> class BI_SListImp : public
  1385.                      BI_ListImp<T>
  1386.                      // sorted list; assumes T has meaningful copy
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.                                   - 24 -
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.                      // semantics and a default constructor
  1400.                      {
  1401.                      public:
  1402.                      ...
  1403.                        void add( T t ) { new BI_ListElement<T>( t,
  1404.                      findPred(t) ); }
  1405.                      // adds object in sorted position
  1406.                      ...
  1407.                      };
  1408.  
  1409.                      template <class T, class List> class
  1410.                      BI_InternalIListImp : public List
  1411.                      {
  1412.                      ...
  1413.                        void add( T *t ) { List::add ( t ); }
  1414.                      };
  1415.                      // The work is done in this intermediate class
  1416.                      // used as base for BI_IListImp; list is
  1417.                      // unsorted so we use List::add
  1418.  
  1419.                      template <class T> class BI_IListImp :
  1420.                      public BI_InternalIListImp<T, BI_ListImp< void * > >
  1421.                      { ... };
  1422.                      /* unsorted list of pointers to objects of type T;
  1423.                         since pointers always have meaningful copy
  1424.                         semantics, this class can handle any object type;
  1425.                         add comes straight from BI_InternalIListImp
  1426.                      */
  1427.  
  1428.                      template <class T> class BI_ISListImp :
  1429.                      public BI_InternalIListImp<T>, BSListImp< void * >> {
  1430.                      ... };
  1431.                      /* sorted list of pointers to objects of type T; since
  1432.                         pointers always have meaningful copy semantics, this
  1433.                         class can handle any object type
  1434.                      */
  1435.  
  1436.                     In addition to the template classes shown here,
  1437.                     listimp.h also declares BI_ListIteratorImp<T> and
  1438.                     BI_IListIteratorImp<T>, the iterators for direct and
  1439.                     indirect lists.
  1440.  
  1441.                     In the next section on ADTs, you'll see how the
  1442.                     different stack implementations in stacks.h pull in the
  1443.                     vector and list FDSs declared in vectimp.h and
  1444.                     listimp.h.
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.                                   - 25 -
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.                     The double list templates, in dlistimp.h, follows the
  1458.                     same pattern. The sorted versions of list and double
  1459.                     list provide exactly the same interface as the non-
  1460.                     sorted ones, except that the add member function adds
  1461.                     new elements in sorted order. This speeds up subsequent
  1462.                     access and also makes it easier to implement priority
  1463.                     queues.
  1464.  
  1465.                     vectimp.h also follows a similar pattern to listimp.h,
  1466.                     implementing BI_VectorImp<T> (direct) and
  1467.                     BI_IVectorImp<T> (indirect). These are low-level vectors
  1468.                     with no notion of add or detach. To support more
  1469.                     sophisticated ADTs, the counted vector,
  1470.                     BI_CVectorImp<T>, derived from BI_VectorImp<T>, is
  1471.                     provided. This maintains a pointer to the last valid
  1472.                     entry in the underlying Vector. It has an add member
  1473.                     function that inserts its argument at the top (the next
  1474.                     available slot), and a detach member function that
  1475.                     removes its argument and compresses the array.
  1476.                     BI_CVectorImp<T> provides the base for the sorted vector
  1477.                     template BI_SVectorImp<T>. With a sorted vector, you can
  1478.                     run through the indices from 0 to the last valid entry,
  1479.                     and the objects will emerge in sort order. Here's a
  1480.                     simplified extract from vectimp.h:
  1481.  
  1482.                      // extract from vectimp.h
  1483.  
  1484.                      template <class T> class BI_VectorImp { ... };
  1485.                      // direct uncounted, unsorted vector
  1486.  
  1487.                      template <class T> class BI_CVectorImp : public
  1488.                      BI_VectorImp<T>
  1489.                      // direct counted, unsorted vector
  1490.                      {
  1491.                      public:
  1492.                      ...
  1493.                        void add( T t );
  1494.                      // add at top of array; inc count; resize array if
  1495.                      necessary
  1496.                        void detach( T t, int del = 0 );
  1497.                        void detach( unsigned loc, int del = 0 );
  1498.                      // detach given object or object at loc
  1499.                      ...
  1500.                      };
  1501.  
  1502.                      template <class T> class BI_SVectorImp : public
  1503.                      BI_CVectorImp<T>
  1504.                      // direct counted, sorted vector
  1505.  
  1506.  
  1507.  
  1508.                                   - 26 -
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                      {
  1516.                      public:
  1517.                        void add( T t );
  1518.                      // add at position that maintains sort
  1519.                      };
  1520.  
  1521.                      template <class T, class Vect> class
  1522.                      BI_InternalIVectorImp :
  1523.                      public Vect {...};
  1524.                      // interdiate base for BI_IVectorImp: no add
  1525.  
  1526.                      template <class T> class BI_IVectorImp :
  1527.                      public BI_InternalIVectorImp<T, BI_VectorImp<void *> >
  1528.                      {...};
  1529.                      // indirect uncounted, unsorted vector: no add
  1530.  
  1531.                      template <class T, class Vect> class
  1532.                      BI_InternalICVectorImp :
  1533.                      public BI_InternalIVectorImp<T, Vect>
  1534.                      // intermediate base for BI_ICVector
  1535.                      {
  1536.                      public:
  1537.                        void add( T *t) { Vect::add(t); }
  1538.                      ...
  1539.                      };
  1540.  
  1541.                      template <class T> class BI_ICVectorImp :
  1542.                      public BI_InternalICVectorImp<T, BI_CVectorImp<void *>
  1543.                      >
  1544.                      { ... };
  1545.                      // indirect counted vector; can contain any object type
  1546.  
  1547.                      template <class T> class BI_ISVectorImp :
  1548.                      public BI_InternalICVectorImp<T, BI_SVectorImp<void *>
  1549.                      >
  1550.                      { ... };
  1551.                      // indirect sorted vector
  1552.  
  1553.  
  1554. ADT implementation  ========================================================
  1555.  
  1556.                     Each ADT is implemented as several templates. For
  1557.                     example, the following provides an implementation of a
  1558.                     stack of objects of type T using vectors as the FDS:
  1559.  
  1560.                      // simplified extract from stacks.h
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.                                   - 27 -
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.                      template <class Vect, class T> class
  1574.                      BI_StackAsVectorImp
  1575.                      {
  1576.                      public:
  1577.                      ...
  1578.                        void push( T t ) { data[current++] = t; }
  1579.                      ...
  1580.  
  1581.                      protected:
  1582.                        Vect data;
  1583.                        unsigned current;
  1584.                      };
  1585.  
  1586.                     The first parameter, class Vect, is either a direct
  1587.                     vector or an indirect vector, depending on whether the
  1588.                     stack being created is direct or indirect, so Vect will
  1589.                     be either BI_VectorImp<T0> or BI_IVectorImp<T0>. The
  1590.                     type T represents the type of objects to be stored in
  1591.                     the stack. For a direct Vect, T should be the same as
  1592.                     T0; for an indirect Vect, T must be of type pointer to
  1593.                     T0. A direct stack implemented as a vector looks like
  1594.                     this:
  1595.  
  1596.                      template <class T> class BI_StackAsVector :
  1597.                          public BI_StackAsVectorImp< BI_VectorImp<T>, T >
  1598.                      {
  1599.                      public:
  1600.                          friend class BI_StackAsVectorIterator<T>;
  1601.                          ...
  1602.                      };
  1603.  
  1604.                      template <class T> class BI_StackAsVectorIterator :
  1605.                          public BI_VectorIteratorImp<T> {...};
  1606.  
  1607.                     That is, a BI_StackAsVector is implemented by using a
  1608.                     BI_StackAsVectorImp, whose "implementation" is of type
  1609.                     BI_VectorImp<T>, and whose elements are of type T.
  1610.                     BI_StackAsVector has its own iterator, derived from
  1611.                     underpinning FDS iterator with the contained-object type
  1612.                     T as parameter.
  1613.  
  1614.                     An indirect stack implemented as a vector looks like
  1615.                     this:
  1616.  
  1617.                      template <class T> class BI_IStackAsVector :
  1618.                          public BI_StackAsVectorImp< BI_IVectorImp<T>, T* >,
  1619.                          public virtual TShouldDelete
  1620.                      {...};
  1621.  
  1622.  
  1623.  
  1624.                                   - 28 -
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.                     That is, an BI_IStackAsVector is implemented by using a
  1632.                     BI_StackAsVectorImp, whose "implementation" is of type
  1633.                     BI_IVectorImp<T>, and whose elements are of type pointer
  1634.                     to T. The TShouldDelete base provides the ownership
  1635.                     control discussed in the Object-based class reference
  1636.                     section. TShouldDelete also serves as a second base for
  1637.                     the following classes.
  1638.  
  1639. Figure 2: TShouldDelete hierarchy
  1640.  
  1641.     TShouldDelete*──────┬──Association*
  1642.                         ├──Container
  1643.                         ├──BI_IArrayAsVector+
  1644.                         ├──BI_IBagAsVector+
  1645.                         ├──BI_IDequeAsDoubleList+
  1646.                         ├──BI_IDequeAsVector+         *Instance classes
  1647.                         ├──BI_ISArrayAsVector+
  1648.                         ├──BI_ISObjectArray+
  1649.                         ├──BI_IStackAsList+           +Template classes
  1650.                         └──BI_IStackAsVector+
  1651.  
  1652.  
  1653.                     The BI_OStackAsVector and BI_TCStackAsVector versions
  1654.                     (stacks of pointers to Objects, emulating the Object
  1655.                     container library) now follow easily:
  1656.  
  1657.                      class BI_OStackAsVector
  1658.                      // non-polymorphic stack with vector of pointers to
  1659.                      Objects
  1660.                      {
  1661.                      public:
  1662.                      ...
  1663.                        void push( Object *t ) { ostack.push(t); }
  1664.                      // ostack is type BI_IStackAsVector<Object>
  1665.                      // so we are pushing pointers to Object
  1666.                      ...
  1667.  
  1668.                      private:
  1669.                        BI_IStackAsVector<Object> ostack;
  1670.                      };
  1671.  
  1672.                      class BI_TCStackAsVector : public Container
  1673.                      // polymorphic stack with vector of pointers to
  1674.                      Objects
  1675.                      // inherits from the Object-based Container class
  1676.                      // Provides identical interface and functionality as
  1677.                      Object-based Stack // class but underlying data
  1678.                      structure is Vector not List
  1679.  
  1680.  
  1681.  
  1682.                                   - 29 -
  1683.  
  1684.  
  1685.  
  1686.  
  1687.  
  1688.  
  1689.                          {
  1690.                      public:
  1691.                      ...
  1692.                        void push( Object& o ) { stk.push( &o ); }
  1693.                      // stk is type BI_OStackAsVector
  1694.                      // so we are pushing Objects
  1695.                      ...
  1696.                      private:
  1697.                        BI_OStackAsVector stk;
  1698.                      };
  1699.  
  1700.  
  1701.                     We end the section with some short examples using the
  1702.                     BIDS classes.
  1703.  
  1704.             Source   #include <iostream.h>
  1705.                      #include <strstream.h>
  1706.  Uses the template   #include <arrays.h>
  1707. facility to pick a   #include <strng.h>
  1708.   specific FDS for
  1709.     the array ADT.   int main()
  1710.                      {
  1711.                         typedef BI_SArrayAsVector<String> lArray;
  1712.     In the "sorted      lArray a(2);
  1713.    array" FDS, the      for (int i = a.arraySize(); i; i--)
  1714.         index of a      {
  1715.   particular array         ostrstream os;
  1716. element depends on         os << "string " << i << ends;
  1717.  its value, not on         a.add( *(new String(os.str())));
  1718. the order in which      }
  1719.    it was entered.      cout << "array elements;\n";
  1720.                         for (i = 0; i < a.arraySize(); ++i)
  1721.                         {
  1722.    If the ADT used         cout<< a[i] << endl;
  1723.   BI_ArrayAsVector      }
  1724.      <String>, the      return(0);
  1725.     elements would   }
  1726.      appear in the
  1727.    order they were
  1728.       added to the
  1729.             array.
  1730.  
  1731.             Output   string 1
  1732.                      string 2
  1733.                      string 3
  1734.  
  1735.             Source
  1736.  
  1737.  
  1738.  
  1739.  
  1740.                                   - 30 -
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747. Doubly-linked list   #include <iostream.h>
  1748.      with indirect   #include <strstream.h>
  1749.    storage as FDS.   #include <deques.h>
  1750.                      #include <strng.h>
  1751.  
  1752. Pointers to String      typedef BI_IDequeAsDoubleList<String> lDeque;
  1753.     objects in the
  1754.    deque container   int main()
  1755.            must be   {
  1756.  dereferenced when      lDeque d;
  1757.    extracting from      for (int i = 1; i < 5; i++)
  1758.         the deque.      {
  1759.                            ostrstream os;
  1760.                            os << "string " << i << ends;
  1761.                            // use alternating left, right insertions
  1762.                            if(i&1)
  1763.                               d.putLeft(new String(os.str()));
  1764.                            else
  1765.                               d.putRight(new String(os.str()));
  1766.                         }
  1767.                         cout << "Deque Contents:" << endl;
  1768.                         while (!d.isEmpty())
  1769.                         {
  1770.                            cout << *d.getLeft() << endl;
  1771.                         }
  1772.                         return(0);
  1773.                      }
  1774.  
  1775.             Output   Deque Contents:
  1776.                      string 3
  1777.                      string 1
  1778.                      string 2
  1779.                      string 4
  1780.  
  1781.  
  1782.  
  1783. ===========================================================================
  1784. The class library directory
  1785. ===========================================================================
  1786.  
  1787.                     The files in the class library are set up in the
  1788.                     following directory structure:
  1789.  
  1790.  
  1791.  
  1792.  
  1793.  
  1794.  
  1795.  
  1796.  
  1797.  
  1798.                                   - 31 -
  1799.  
  1800.  
  1801.  
  1802.  
  1803.  
  1804.  
  1805.                              ╔═══════════╗
  1806.                              ║ CLASSLIB\ ║
  1807.                              ╚═════╤═════╝
  1808.      ┌──────────────┬──────────────┼───────────┬────────────┐
  1809. ╔════╧═════╗   ╔════╧════╗   ┌─────┴────┐   ╔══╧═══╗   ╔════╧══════╗
  1810. ║ INCLUDE\ ║   ║ SOURCE\ ║   │   OBJS   │   ║ LIB\ ║   ║ EXAMPLES\ ║
  1811. ╚══════════╝   ╚═════════╝   └──────────┘   ╚══════╝   ╚═══════════╝
  1812.  
  1813.                     The CLASSLIB directory is under the TC directory. The
  1814.                     contents of the directories in the class library are
  1815.                     discussed in more detail in the following sections.
  1816.  
  1817.  
  1818.        The INCLUDE  =======================================================
  1819.          directory
  1820.                     The INCLUDE directory contains the header files
  1821.                     necessary to compile a program that uses the class
  1822.                     library. You must put this directory on the include
  1823.                     search path when you compile your program. Modify
  1824.                     Options|Directories|Include Directories if you changed
  1825.                     the default setup.
  1826.  
  1827.                     For each BIDS ADT (abstract data type), such as Stack,
  1828.                     there is a header file called stacks.h. The Object-
  1829.                     based class Stack is declared in stack.h. If the
  1830.                     identifier TEMPLATES is #defined, either in an .h file
  1831.                     or via the command line _D option, then when stack.h is
  1832.                     preprocessed, the Object-based declarations for Stack
  1833.                     are bypassed and the template versions are included. In
  1834.                     particular, if TEMPLATES is #defined, Stack is #defined
  1835.                     as BI_TCStackAsList, so any code written for the
  1836.                     Object-based Stack will be compiled with the BIDS
  1837.                     version.
  1838.  
  1839.  
  1840. The OBJS directory  =======================================================
  1841.  
  1842.                     Subdirectories of the OBJS directory contain .PRJ file
  1843.                     samples.
  1844.  
  1845.  
  1846.         The SOURCE  =======================================================
  1847.          directory
  1848.                     The SOURCE directory contains the source files that
  1849.                     implement many of the member functions of the classes
  1850.                     in the library. These source files are provided as a
  1851.                     guide for implementing new classes.
  1852.  
  1853.  
  1854.  
  1855.  
  1856.                                   - 32 -
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.                     You also need these source files if you want to build a
  1864.                     library. There are project files for small and large
  1865.                     models, debug and non-debug versions, and template and
  1866.                     non-template versions.
  1867.  
  1868.  
  1869. ------------------  To create a new library using the small memory model,
  1870. Creating a library  proceed as follows:
  1871. ------------------
  1872.                     1. Open the CLASSLIBS\OBJS\S (for standard or BIDS) or
  1873.                        CLASSLIBS\OBJS\DBS (for debug) directory.
  1874.  
  1875.                     2. Create a directory for the new library.
  1876.  
  1877.                     3. Copy the project file that's closest to the one you
  1878.                        want to create to that directory (use TCLASSS.PRJ to
  1879.                        create a standard classlib, TCLASDBS.PRJ to create a
  1880.                        debug version, or BIDSS.PRJ to create a templatized
  1881.                        version).
  1882.  
  1883.                     4. Rename the project file to TCLASSS.PRJ.
  1884.  
  1885.                     5. Run TC and select Project|Open TCLASSS.PRJ.
  1886.  
  1887.                     6. Set Options|Compiler|Code Generation to the small
  1888.                        memory model.
  1889.  
  1890.                     7. Select Compile|Build all.
  1891.  
  1892.                     8. Copy the resultant .LIB file to the CLASSLIB\LIB
  1893.                        directory.
  1894.  
  1895.                     For a large memory model, in step 2 copy a xL.PRJ file
  1896.                     and in step 3 rename it to TCLASSL.PRJ.
  1897.  
  1898.         Important!  When you take a library that you have built and use it
  1899.                     in one of the sample projects, you must update the
  1900.                     project. See Chapter 7, "Managing multi-file projects"
  1901.                     for more information. You must also be sure to compile
  1902.                     your project with precisely the same switches and op-
  1903.                     tions you used to build the library. If you don't have
  1904.                     the same options, you will get warnings from the linker
  1905.                     when the executable file is built.
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.                                   - 33 -
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  The LIB directory  =======================================================
  1922.  
  1923.                     The LIB directory contains the compiled source modules
  1924.                     archived into a library. You must put this directory on
  1925.                     the library search path when you link your program. For
  1926.                     information about modifying the library search path,
  1927.                     see Chapter 8, "The command-line compiler" (for
  1928.                     command-line options).
  1929.  
  1930.                     The Object-based container classes are in TCLASSx.LIB,
  1931.                     where x is the memory-model designation (S for small, C
  1932.                     for compact, M for medium, L for large, and H for
  1933.                     huge). For each of these there are debugging versions
  1934.                     TCLASDBx.LIB.
  1935.  
  1936.  
  1937.       The EXAMPLES  =======================================================
  1938.          directory
  1939.                     The CLASSLIB\EXAMPLES directory contains the example
  1940.                     programs and their project files. You can compile these
  1941.                     programs to see how the parts of the class library are
  1942.                     put together to form an application. Most of the
  1943.                     examples use one or two of the classes in the
  1944.                     hierarchy; other examples are more complex. Here is a
  1945.                     list of the example programs and the classes that they
  1946.                     use:
  1947.  
  1948.                     1. STRNGMAX: A very simple example using String.
  1949.  
  1950.                     2. REVERSE: An intermediate example using Stack and
  1951.                        String.
  1952.  
  1953.                     3. LOOKUP: An intermediate example using Dictionary and
  1954.                        Association.
  1955.  
  1956.                     4. QUEUETST: An intermediate example using Queue and
  1957.                        introducing a non-hierarchical class, Time.
  1958.  
  1959.                     5. DIRECTRY: An advanced example illustrating derived
  1960.                        user classes with SortedArray.
  1961.  
  1962.  
  1963.  
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.                                   - 34 -
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979. ===========================================================================
  1980. Preconditions and checks
  1981. ===========================================================================
  1982.  
  1983.                     Version 3.0 offers some new debugging tools. The class
  1984.                     libraries TCLASDBx.LIB and BIDSDBx.LIB (where x
  1985.                     represents the memory model, S, C, L, M, or H) provide
  1986.                     the debugging versions of TCLASSx.LIB and BIDSx.LIB.
  1987.  
  1988.                     checks.h defines two macros, PRECONDITION( arg ) and
  1989.                     CHECK( arg ). Each macro takes an arbitrary expression
  1990.                     as an argument, just like assert. At runtime, if the
  1991.                     expression evaluates to 0, an error message is
  1992.                     displayed and execution terminates. If the expression
  1993.                     evaluates to a nonzero value, execution continues in
  1994.                     the normal fashion.
  1995.  
  1996.                     Use PRECONDITION on entry to a function to check the
  1997.                     validity of the arguments and to do any other checking
  1998.                     to determine that the function has been invoked
  1999.                     correctly.
  2000.  
  2001.                     Use CHECK for internal checking during the course of
  2002.                     execution of the function.
  2003.  
  2004.                     Compilation of PRECONDITION and CHECK is controlled by
  2005.                     the value of a manifest constant named __DEBUG. If
  2006.                     __DEBUG has the value 0, PRECONDITION and CHECK are set
  2007.                     to empty macros. In other words, setting __DEBUG to 0
  2008.                     removes all debugging. If __DEBUG has the value 1,
  2009.                     PRECONDITION macros are expanded into the tests
  2010.                     described above, but CHECK macros are empty. So,
  2011.                     setting __DEBUG to 1 enables PRECONDITIONs and disables
  2012.                     CHECKs. Setting __DEBUG to 2 or more, or not defining
  2013.                     it at all, enables both forms of testing. Table 6
  2014.                     summarizes the available debugging modes:
  2015.  
  2016.  
  2017.                     -----------------------------------------------------------------
  2018.  Class debugging      __DEBUG      PRECONDITION    CHECK
  2019.            modes    -----------------------------------------------------------------
  2020.  
  2021.                       0               Off           Off
  2022.                       1               On            Off
  2023.                       >1              On            On
  2024.                       undefined       On            On
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.                                   - 35 -
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.                     -----------------------------------------------------------------
  2038.  
  2039.                     When developing a class, set __DEBUG to 2 or leave it
  2040.                     undefined. This gives you maximum checking when the
  2041.                     code is still being worked on. When the class works
  2042.                     properly, but the application that is going to use the
  2043.                     class hasn't been completed, set __DEBUG to 1, so that
  2044.                     incorrect calls from the application can be caught,
  2045.                     without the additional overhead of the internal
  2046.                     checking within the class. Once everything is working,
  2047.                     set __DEBUG to 0 to remove all checking. Two versions
  2048.                     of the .LIB file are provided that contain the class
  2049.                     library code: one with PRECONDITIONs enabled, and one
  2050.                     with no debugging. These are named TCLASDBX.LIB and
  2051.                     TCLASSX.LIB, where X is replaced with the letter for
  2052.                     the appropriate memory model: s, c, m, l, or h. The
  2053.                     .LIB with DB in its name is the one with PRECONDITIONs
  2054.                     enabled.
  2055.  
  2056.  
  2057.  
  2058. ===========================================================================
  2059. Container class reference
  2060. ===========================================================================
  2061.  
  2062.                     This section describes each class in the library as
  2063.                     follows. We give the include file where it is defined,
  2064.                     a diagram showing the parent of each class and
  2065.                     immediate offspring, some introductory remarks, data
  2066.                     members and member functions (with protoypes) listed
  2067.                     alphabetically, what friendly relations exist, and,
  2068.                     where appropriate, an example of the class's use. The
  2069.                     members listed in the See also section belong to the
  2070.                     class under discussion unless scope-qualified. Thus in
  2071.                     the section on class X, you could find See also foo,
  2072.                     Y::foo, and so on. The first foo refers to X::foo.
  2073.                     Class derivations and class members are public unless
  2074.                     otherwise noted as protected. We do not document
  2075.                     destructors since they all perform the usual way. Most
  2076.                     container classes have virtual destructors.
  2077.  
  2078.  
  2079.  
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.  
  2088.                                   - 36 -
  2089.  
  2090.  
  2091.                                                               AbstractArray
  2092.  
  2093.  
  2094.  
  2095. ===========================================================================
  2096. AbstractArray                                                    abstarry.h
  2097. ===========================================================================
  2098.  
  2099.                     ┌────────────┐  ╔═════════════╗   ┌────────────┐
  2100.                     │ Collection ├──╢AbstractArray╟─┬─┤   Array    │
  2101.                     └────────────┘  ╚═════════════╝ │ └────────────┘
  2102.                                                     │ ┌────────────┐
  2103.                                                     └─┤SortedArray │
  2104.                                                       └────────────┘
  2105.                     The abstract class AbstractArray offers random access
  2106.                     to the elements of the collection via an indexing
  2107.                     mechanism that maps a range of integers to the array
  2108.                     elements. Indexes can be positive or negative integers
  2109.                     with arbitrary lower and upper bounds (within the range
  2110.                     of int). Arrays derived from AbstractArray can be
  2111.                     dynamically resized as elements are added to them. The
  2112.                     data member delta determines how many additional
  2113.                     elements are assigned to the array when overflow
  2114.                     occurs. AbstractArray exists because the derived
  2115.                     classes SortedArray and Array have enough in common to
  2116.                     warrant combining the common properties into an
  2117.                     abstract base class. Since the derived classes differ
  2118.                     only in the implementation of the member functions
  2119.                     detach and the subscript operator, the remaining
  2120.                     functions can be encapsulated in AbstractArray.
  2121.  
  2122.  
  2123.       Data members  =======================================================
  2124.  
  2125.  
  2126.              delta  sizeType delta;                               protected
  2127.  
  2128.                     delta represents the additional number of elements that
  2129.                     will be assigned to the array if overflow occurs. If
  2130.                     delta is zero, the array will not be resized following
  2131.                     overflow.
  2132.  
  2133.   lastElementIndex  int lastElementIndex;                         protected
  2134.  
  2135.                     The index value of the last element added to the array.
  2136.                     For an empty array this data member has the value
  2137.                     (lowerbound - 1).
  2138.  
  2139.         lowerbound  int lowerbound;                               protected
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.                                   - 37 -
  2147.  
  2148.  
  2149. AbstractArray
  2150.  
  2151.  
  2152.  
  2153.                     The lower bound of the array index, returned by the
  2154.                     lowerBound member function. lowerbound is the minimum
  2155.                     legal value of the absolute index.
  2156.  
  2157.                     See also: lowerBound
  2158.  
  2159.         upperbound  int upperbound;                               protected
  2160.  
  2161.                     The current upper bound of the array index, returned by
  2162.                     the upperBound member function. upperbound is the
  2163.                     maximum legal value of the absolute index.
  2164.  
  2165.                     See also: upperBound
  2166.  
  2167.  
  2168.   Member functions  =======================================================
  2169.  
  2170.  
  2171.            destroy  void destroy( int atIndex );
  2172.  
  2173.                     Removes the object at the given index. Whether the
  2174.                     object itself is destroyed or not depends on the
  2175.                     array's ownership status. If the array currently owns
  2176.                     the object, the object will be destroyed, otherwise the
  2177.                     object survives. destroy is implemented with detach(
  2178.                     atIndex, DefDelete ).
  2179.  
  2180.  
  2181.          arraySize  sizeType arraySize() const;
  2182.  
  2183.                     Returns the current number of cells allocated
  2184.                     (upperbound - lowerbound + 1).
  2185.  
  2186.        constructor  AbstractArray( int anUpper, int aLower = 0, sizeType
  2187.                     aDelta = 0 );
  2188.  
  2189.                     Constructs and "zeroes" an array, given the upper and
  2190.                     lower index bounds. The default lower bound is 0, the
  2191.                     traditional origin for C arrays. The default delta is
  2192.                     also zero, giving a fixed, nonresizable array. If delta
  2193.                     is nonzero, run-time array overflow invokes the
  2194.                     reallocate member function to provide more space (in
  2195.                     increments of delta). A PRECONDITION is set to test if
  2196.                     the lower bound is greater than or equal to the lower
  2197.                     bound.
  2198.  
  2199.             detach  virtual void detach( int atIndex, DeleteType dt =
  2200.                     NoDelete );
  2201.  
  2202.  
  2203.  
  2204.                                   - 38 -
  2205.  
  2206.  
  2207.                                                               AbstractArray
  2208.  
  2209.  
  2210.  
  2211.                     virtual void detach( Object& toDetach, DeleteType dt =
  2212.                     NoDelete );
  2213.  
  2214.                     The first version removes the object at atIndex; the
  2215.                     second version removes the object toDetach. The value
  2216.                     of dt and the current ownership setting determine
  2217.                     whether the object itself will be deleted. DeleteType
  2218.                     is defined in the base class TShouldDelete as enum {
  2219.                     NoDelete, DefDelete, Delete }. The default value of dt,
  2220.                     NoDelete, means that the object will not be deleted
  2221.                     regardless of ownership. With dt set to Delete, the
  2222.                     object will be deleted regardless of ownership. If dt
  2223.                     is set to DefDelete, the object will only be deleted if
  2224.                     the array owns its elements.
  2225.  
  2226.                     See also: TShouldDelete::ownsElements
  2227.  
  2228.       initIterator  virtual ContainerIterator& initIterator() const;
  2229.  
  2230.                     Creates an external iterator for this array.
  2231.  
  2232.                     See also: ContainerIterator class
  2233.  
  2234.            isEqual  int isEqual( const Object& testObject ) const;
  2235.  
  2236.                     Returns 1 if the testObject array is equal to the
  2237.                     calling array. Equal means that the two arrays have the
  2238.                     same object ID, the arrays' dimensions are equal, and
  2239.                     that their components are equal in each index position.
  2240.                     Otherwise, isEqual returns 0.
  2241.  
  2242.         lowerBound  int lowerBound() const;
  2243.  
  2244.                     Returns the array's lowerbound.
  2245.  
  2246.           objectAt  Object& objectAt( int atIndex ) const;        protected
  2247.  
  2248.                     Returns a reference to the element at the given index.
  2249.  
  2250.                     See also: operator []
  2251.  
  2252.        operator []  Object& operator []( int atIndex ) const;
  2253.  
  2254.                     Returns a reference to the object at the given array
  2255.                     index.
  2256.  
  2257.    printContentsOn  void printContentsOn( ostream& outputStream ) const;
  2258.  
  2259.  
  2260.  
  2261.  
  2262.                                   - 39 -
  2263.  
  2264.  
  2265. AbstractArray
  2266.  
  2267.  
  2268.  
  2269.                     Prints an array, with header and trailer, to the given
  2270.                     stream.
  2271.  
  2272.              ptrAt  Object *ptrAt( int atIndex ) const;           protected
  2273.  
  2274.                     Returns a pointer to the element at the given index.
  2275.  
  2276.         reallocate  void reallocate( sizeType newSize );          protected
  2277.  
  2278.                     If delta is zero, reallocate gives an __EEXPANDFS
  2279.                     error. Otherwise, reallocate tries to create a new
  2280.                     array of size newSize (adjusted upwards to the nearest
  2281.                     multiple of delta). The existing array is copied to the
  2282.                     expanded array and then deleted. Unused elements in the
  2283.                     new array are zeroed. An __ENOMEM error is invoked if
  2284.                     there is insufficient memory for the reallocation.
  2285.  
  2286.        removeEntry  void removeEntry( int loc );                  protected
  2287.  
  2288.                     Reduces the array by one element. Elements from index
  2289.                     (loc + 1) upwards are copied to positions loc, (loc +
  2290.                     1), and so on. The original element at loc is lost.
  2291.  
  2292.            setData  void setData( int loc, Object *data );        protected
  2293.  
  2294.                     The given data replaces the existing element at the
  2295.                     index loc.
  2296.  
  2297.       squeezeEntry  void squeezeEntry( int squeezePoint );        protected
  2298.  
  2299.                     Reduces the array by one element. As for removeEntry
  2300.                     but squeezePoint is an index relative to the lower
  2301.                     bound
  2302.  
  2303.         upperBound  int upperBound() const;
  2304.  
  2305.                     Returns the array's current upperbound.
  2306.  
  2307.  
  2308.            Friends  =======================================================
  2309.  
  2310.                     ArrayIterator is a friend of AbstractArray
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316.  
  2317.  
  2318.  
  2319.  
  2320.                                   - 40 -
  2321.  
  2322.  
  2323.                                                                       Array
  2324.  
  2325.  
  2326.  
  2327. ===========================================================================
  2328. Array                                                               array.h
  2329. ===========================================================================
  2330.  
  2331.                     ┌─────────────┐  ╔════════════╗
  2332.                     │AbstractArray├──╢   Array    ║
  2333.                     └─────────────┘  ╚════════════╝
  2334.  
  2335.                     The instance class Array is derived from class
  2336.                     AbstractArray. An Array object defines an array in
  2337.                     which the ordering of the elements is arbitrary. That
  2338.                     is, the element at index i of the array need have no
  2339.                     relationship to the element at index i + 1.
  2340.  
  2341.                     Array adds the functions add and addAt. While add
  2342.                     stores a given object at the next free place in the
  2343.                     array (expanding the array if necessary), addAt stores
  2344.                     the object at a specified index.
  2345.  
  2346.  
  2347.            Example  =======================================================
  2348.  
  2349.             Source   #include <iostream.h>
  2350.                      #include <array.h>
  2351.                      #include <strng.h>
  2352.                      #include <assoc.h>
  2353.  
  2354.                      int main()
  2355.                      {
  2356.                          Array a(2);
  2357.  
  2358.                          String *s1 = new String("a string");
  2359.                          String *s2 = new String("another string");
  2360.                          Association *a1 = new Association(*s1,*s2);
  2361.  
  2362.                          // Put some objects in the array
  2363.                          a.add(*s1);
  2364.                          a.add(*s2);
  2365.                          a.add(*a1);
  2366.  
  2367.                          // Print as a Container
  2368.                          cout << "As a container:\n" << a << endl << endl;
  2369.  
  2370.                          // Print as an Array
  2371.                          cout << "As an array:\n";
  2372.                          a.printContentsOn(cout);
  2373.  
  2374.                          // Print as elements
  2375.  
  2376.  
  2377.  
  2378.                                   - 41 -
  2379.  
  2380.  
  2381. Array
  2382.  
  2383.  
  2384.  
  2385.                          cout << "\nAs elements:\n";
  2386.                          for (int i = 0; i < a.arraySize(); ++i)
  2387.                              cout << a[i] << endl;
  2388.                          return(0);
  2389.                      }
  2390.  
  2391.             Output   As a container:
  2392.                      Array { a string,
  2393.                          another atring,
  2394.                           Association { a string, another string }
  2395.                       }
  2396.  
  2397.                      As an array:
  2398.                      Array { a string,
  2399.                          another atring,
  2400.                           Association { a string, another string }
  2401.                       }
  2402.  
  2403.                      As elements:
  2404.                      a string
  2405.                      another string
  2406.                      Association { a string, another string}
  2407.  
  2408.  
  2409.   Member functions  =======================================================
  2410.  
  2411.  
  2412.                add  virtual void add( Object& toAdd );
  2413.  
  2414.                     Adds the given object at the next available index at
  2415.                     the end of an array. Adding an element beyond the upper
  2416.                     bound leads to an overflow condition. If overflow
  2417.                     occurs and delta is nonzero, the array is expanded (by
  2418.                     sufficient multiples of delta bytes) to accommodate the
  2419.                     addition. If delta is zero, overflow gives an error.
  2420.  
  2421.              addAt  void addAt( Object& toAdd, int atIndex );
  2422.  
  2423.                     Writes the given object at the specified index. If that
  2424.                     index is occupied, the previous object is deleted. If
  2425.                     atIndex is beyond the upper bound, the array is
  2426.                     expanded if delta is nonzero. If delta is zero,
  2427.                     attempting to addAt beyond the upper bound gives an
  2428.                     error.
  2429.  
  2430.        constructor  Array( int anUpper, int aLower = 0, sizeType Delta = 0
  2431.                     );
  2432.  
  2433.  
  2434.  
  2435.  
  2436.                                   - 42 -
  2437.  
  2438.  
  2439.                                                                       Array
  2440.  
  2441.  
  2442.  
  2443.                     Constructs and "zeroes" an array by calling the base
  2444.                     AbstractArray constructor.
  2445.  
  2446.                     See also: AbstractArray::AbstractArray
  2447.  
  2448.                isA  virtual classType isA() const;
  2449.  
  2450.                     Returns arrayClass, the Arrays type ID.
  2451.  
  2452.             nameOf  virtual char *nameOf() const;
  2453.  
  2454.                     Returns "Array", the Array type ID string.
  2455.  
  2456.  
  2457.  
  2458. ===========================================================================
  2459. ArrayIterator                                                    abstarry.h
  2460. ===========================================================================
  2461.  
  2462.                     ┌─────────────────┐  ╔══════════════════╗
  2463.                     │ContainerIterator├──╢  ArrayIterator   ║
  2464.                     └─────────────────┘  ╚══════════════════╝
  2465.                     Provides iterator functions to traverse objects of the
  2466.                     class AbstractArray and its derived classes.
  2467.                     ArrayIterator is a friend class of AbstractArray
  2468.  
  2469.  
  2470.   Member functions  =======================================================
  2471.  
  2472.  
  2473.        constructor  ArrayIterator( const AbstractArray& toIterate );
  2474.  
  2475.                     Creates an iterator object for the given array.
  2476.  
  2477.                     See also: restart
  2478.  
  2479.            current  virtual Object& current();
  2480.  
  2481.                     Returns the object at the current index of the
  2482.                     iterator. If the current index doesn't refer to a valid
  2483.                     object, NOOBJECT is returned.
  2484.  
  2485.        operator ++  virtual Object& operator ++ ();
  2486.                     virtual Object& operator ++ ( int );
  2487.  
  2488.                     See ContainerIterator operator ++
  2489.  
  2490.     operator int()  virtual operator int();
  2491.  
  2492.  
  2493.  
  2494.                                   - 43 -
  2495.  
  2496.  
  2497. ArrayIterator
  2498.  
  2499.  
  2500.  
  2501.                     Conversion operator to test for end of iterator
  2502.                     position.
  2503.  
  2504.            restart  virtual void restart();
  2505.  
  2506.                     Sets the current index of the iterator to the first
  2507.                     nonempty object in the array.
  2508.  
  2509.  
  2510.  
  2511. ===========================================================================
  2512. Association                                                         assoc.h
  2513. ===========================================================================
  2514.  
  2515.                     ┌────────────┐  ╔════════════╗
  2516.                     │   Object   ├──╢Association ║
  2517.                     └────────────┘  ╚════════════╝
  2518.  
  2519.                     The Association class provides a simple mechanism for
  2520.                     associating two objects, known as the value object and
  2521.                     the key object, in one Association type object. These
  2522.                     combined objects are typically stored in a Dictionary
  2523.                     type object, which provides member functions to
  2524.                     retrieve the value when given the key, providing the
  2525.                     basic tools for many data-retrieval applications.
  2526.  
  2527.  
  2528.   Member functions  =======================================================
  2529.  
  2530.  
  2531.        constructor  Association( Object& key, Object& value );
  2532.  
  2533.                     Constructs an association object from the given key and
  2534.                     value objects.
  2535.  
  2536.        constructor  Association( const Association& a );
  2537.  
  2538.                     Copy constructor.
  2539.  
  2540.          hashValue  virtual hashValueType hashValue() const;
  2541.  
  2542.                     Returns the hash value of the association's key. See
  2543.                     HashTable::hashValue for more details.
  2544.  
  2545.                isA  virtual classType isA() const;
  2546.  
  2547.                     Returns associationClass, the Association type ID.
  2548.  
  2549.  
  2550.  
  2551.  
  2552.                                   - 44 -
  2553.  
  2554.  
  2555.                                                                 Association
  2556.  
  2557.  
  2558.  
  2559.      isAssociation  virtual int isAssociation() const;
  2560.  
  2561.                     Returns 1 for association objects (and 0 for other
  2562.                     object types).
  2563.  
  2564.            isEqual  virtual int isEqual( const Object& toObject ) const;
  2565.  
  2566.                     Returns 1 if toObject and the calling association have
  2567.                     equal keys, otherwise returns 0.
  2568.  
  2569.                key  Object& key() const;
  2570.  
  2571.                     Returns the key object of the association.
  2572.  
  2573.             nameOf  virtual char *nameOf() const;
  2574.  
  2575.                     Returns "Association", the Association type ID string.
  2576.  
  2577.            printOn  virtual void printOn( ostream& outputStream ) const;
  2578.  
  2579.   operator << is a  Prints the association on the given output stream.
  2580.  friend of Object.  printOn is really for internal use by the overloaded
  2581.       See page 87.  operator <<.
  2582.  
  2583.              value  Object& value() const;
  2584.  
  2585.                     Returns the value object of the association.
  2586.  
  2587.            Example  =======================================================
  2588.  
  2589.             Source   // File TASSOC.CPP: Illustrates the Association class
  2590.  
  2591.                      #include <string.h>     // For strlen()
  2592.                      #include <strng.h>
  2593.                      #include <assoc.h>
  2594.                      #include <iostream.h>
  2595.  
  2596.                      void identify(Object&);
  2597.  
  2598.                      main()
  2599.                      {
  2600.                          char s1[21], s2[81];
  2601.  
  2602.                          // Read a key
  2603.                          cout << "Enter a key: ";
  2604.                          cin >> s1;
  2605.                          cin.get();          // Eat newline
  2606.  
  2607.  
  2608.  
  2609.  
  2610.                                   - 45 -
  2611.  
  2612.  
  2613. Association
  2614.  
  2615.  
  2616.  
  2617.                          String str1(s1);
  2618.                          identify(str1);
  2619.  
  2620.                          // Read a value
  2621.                          cout << "Enter a value: ";
  2622.                          cin.getline(s2,81);
  2623.                          s2[strlen(s2) - 1] = '\0';
  2624.                          String str2(s2);
  2625.                          identify(str2);
  2626.  
  2627.                          Association a1(str1,str2);
  2628.                          identify(a1);
  2629.                          Association a2 = a1;
  2630.                          identify(a2);
  2631.  
  2632.                          cout << "Equal: " << a1.isEqual(a2) << endl;
  2633.                      }
  2634.  
  2635.                      void identify(Object& o)
  2636.                      {
  2637.                          // Echo an object and its type
  2638.                          cout << "Value: " << o
  2639.                               << ", Object type: " << o.nameOf()
  2640.                               << endl << endl;
  2641.                      }
  2642.  
  2643.             Output   Enter a key: class
  2644.                      Value: class, Object type: String
  2645.  
  2646.                      Enter a value: A group of related objects
  2647.                      Value: A group of related objects, Object type: String
  2648.  
  2649.                      Value:  Association { class, A group of related
  2650.                      objects }
  2651.                      , Object type: Association
  2652.  
  2653.                      Value:  Association { class, A group of related
  2654.                      objects }
  2655.                      , Object type: Association
  2656.  
  2657.                      Equal: 1
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.                                   - 46 -
  2669.  
  2670.  
  2671.                                                                         Bag
  2672.  
  2673.  
  2674.  
  2675. ===========================================================================
  2676. Bag                                                                   bag.h
  2677. ===========================================================================
  2678.  
  2679.                     ┌────────────┐  ╔════════════╗  ┌────────────┐
  2680.                     │ Collection ├──╢    Bag     ╟──┤    Set     │
  2681.                     └────────────┘  ╚════════════╝  └────────────┘
  2682.                     A Bag is an unordered collection that may contain more
  2683.                     than one of the same object. Bag also provides the base
  2684.                     class for Set. Unlike Bags, Sets can contain only one
  2685.                     copy of a any given object.
  2686.  
  2687.  
  2688.   Member functions  =======================================================
  2689.  
  2690.  
  2691.                add  virtual void add( Object& toAdd );
  2692.  
  2693.                     Adds the given object at the next available index at
  2694.                     the end of an array. Adding an element beyond the upper
  2695.                     bound leads to an overflow condition. If overflow
  2696.                     occurs and delta is nonzero, the array is expanded (by
  2697.                     sufficient multiples of delta bytes) to accommodate the
  2698.                     addition. If delta is zero, overflow gives an error.
  2699.  
  2700.        constructor  Bag( sizeType bagSize = DEFAULT_BAG_SIZE );
  2701.  
  2702.                     Constructs an empty bag. bagSize represents the initial
  2703.                     number of slots allocated.
  2704.  
  2705.             detach  virtual void detach( Object& toDetach, DeleteType dt =
  2706.                     NoDelete );
  2707.  
  2708.                     See Array::detach.
  2709.  
  2710.         findMember  virtual Object& findMember( Object& toFind ) const;
  2711.  
  2712.                     Returns the given object if found, otherwise returns
  2713.                     NOOBJECT.
  2714.  
  2715.          firstThat  virtual Object& firstThat( condFuncType testFuncPtr,
  2716.                     void *paramList ) const;
  2717.  
  2718.                     See also:   Container::firstThat, Object::firstThat
  2719.  
  2720.              flush  void flush( DeleteType dt = DefDelete );
  2721.  
  2722.  
  2723.  
  2724.  
  2725.  
  2726.                                   - 47 -
  2727.  
  2728.  
  2729. Bag
  2730.  
  2731.  
  2732.  
  2733.                     Removes all the elements from the bag without
  2734.                     destroying the bag. The value of dt determines whether
  2735.                     the elements themselves are destroyed. By default, the
  2736.                     ownership status of the bag determines their fate, as
  2737.                     explained in the detach member function. You can also
  2738.                     set dt to Delete and NoDelete.
  2739.  
  2740.                     See also: detach
  2741.  
  2742.            forEach  void forEach( void ( *actionFuncPtr)(Object& o, void
  2743.                     *), void *args );
  2744.  
  2745.                     See also:   Container::forEach
  2746.  
  2747. getItemsInContainer countType getItemsInContainer() const;
  2748.  
  2749.                     Returns the number of items in the bag.
  2750.  
  2751.          hasMember  virtual int hasMember( const Object& obj ) const;
  2752.  
  2753.                     Returns 1 if the given object is found in the bag,
  2754.                     otherwise returns 0.
  2755.  
  2756.       initIterator  ContainerIterator& initIterator() const;
  2757.  
  2758.                     Creates and returns an iterator for this bag.
  2759.  
  2760.                     See also: ContainerIterator class
  2761.  
  2762.                isA  virtual classType isA() const;
  2763.  
  2764.                     Returns bagClass the Bag type ID.
  2765.  
  2766.            isEmpty  int isEmpty() const;
  2767.  
  2768.                     Returns 1 if a container has no elements; otherwise
  2769.                     returns 0.
  2770.  
  2771.           lastThat  virtual Object& lastThat( condFuncType testFuncPtr,
  2772.                     void *paramList ) const;
  2773.  
  2774.                     Returns a reference to the last object in the container
  2775.                     that satisfies a given condition. You supply a
  2776.                     testFuncPtr that returns true for a certain condition.
  2777.                     You can pass arbitrary arguments via the paramList
  2778.                     argument. NOOBJECT is returned if no object in the
  2779.                     container meets the condition. Note that you are not
  2780.                     involved directly with iterators: firstThat and
  2781.  
  2782.  
  2783.  
  2784.                                   - 48 -
  2785.  
  2786.  
  2787.                                                                         Bag
  2788.  
  2789.  
  2790.  
  2791.                     lastThat create their own internal iterators, so you
  2792.                     can simply treat them as "search" functions.
  2793.  
  2794.                     See also:   firstThat, Object::firstThat,
  2795.                     Container::lastThat
  2796.  
  2797.             nameOf  virtual char *nameOf() const;
  2798.  
  2799.                     Returns "Bag", the Bag type ID string.
  2800.  
  2801.       ownsElements  int ownsElements();
  2802.                     void ownsElements( int del );
  2803.  
  2804.                     See TShouldDelete::ownsElements
  2805.  
  2806.  
  2807.  
  2808. ===========================================================================
  2809. BaseDate                                                            ldate.h
  2810. ===========================================================================
  2811.  
  2812.                     ┌────────────┐  ╔════════════╗  ┌────────────┐
  2813.                     │  Sortable  ├──╢  BaseDate  ╟──┤    Date    │
  2814.                     └────────────┘  ╚════════════╝  └────────────┘
  2815.                     BaseDate is an abstract class derived from Sortable
  2816.                     that provides basic date manipulation functions.
  2817.  
  2818.  
  2819.   Member functions  =======================================================
  2820.  
  2821.  
  2822.        constructor  BaseDate();                                   protected
  2823.  
  2824.                     Creates a BaseDate object with the current system date.
  2825.  
  2826.        constructor  BaseDate( unsigned char M, unsigned char D, unsigned Y
  2827.                     );                                            protected
  2828.  
  2829.                     Creates a BaseDate object with the given month, day,
  2830.                     and year.
  2831.  
  2832.        constructor  BaseDate( const BaseDate& BD );               protected
  2833.  
  2834.                     Copy constructor.
  2835.  
  2836.                Day  unsigned Day() const;
  2837.  
  2838.                     Returns the day of the month.
  2839.  
  2840.  
  2841.  
  2842.                                   - 49 -
  2843.  
  2844.  
  2845. BaseDate
  2846.  
  2847.  
  2848.  
  2849.          hashValue  virtual hashValueType hashValue() const;
  2850.  
  2851.                     Returns the hash value of the date object. See
  2852.                     HashTable::hashValue for more details.
  2853.  
  2854.                isA  virtual classType isA() const = 0;
  2855.  
  2856.                     A pure virtual function to return a classtype ID (to be
  2857.                     defined in  derived classes).
  2858.  
  2859.            isEqual  virtual int isEqual( const Object& testDate ) const;
  2860.  
  2861.                     Returns 1 if the object represents the same date as
  2862.                     testDate. Otherwise returns 0.
  2863.  
  2864.         isLessThan  virtual int isLessThan( const Object& testDate ) const;
  2865.  
  2866.                     Returns 1 if the object precedes testDate on the
  2867.                     calendar.
  2868.  
  2869.              Month  unsigned Month() const;
  2870.  
  2871.                     Returns the month.
  2872.  
  2873.             nameOf  virtual char *nameOf() const = 0;
  2874.  
  2875.                     Pure virtual function to be defined by derived classes
  2876.                     to return their object ID string.
  2877.  
  2878.            printOn  virtual void printOn( ostream& outputStream ) const =
  2879.                     0;
  2880.  
  2881.   operator << is a  Pure virtual function to be defined in derived classes
  2882.  friend of Object.  to print the date object on the given stream. printOn
  2883.       See page 87.  is for internal use by the overloaded operator <<.
  2884.  
  2885.             SetDay  void SetDay( unsigned char D );
  2886.  
  2887.                     Sets the day to D.
  2888.  
  2889.           SetMonth  void SetMonth( unsigned char M );
  2890.  
  2891.                     Sets the month to M.
  2892.  
  2893.            SetYear  void SetYear( unsigned Y );
  2894.  
  2895.                     Sets the year to Y.
  2896.  
  2897.  
  2898.  
  2899.  
  2900.                                   - 50 -
  2901.  
  2902.  
  2903.                                                                    BaseDate
  2904.  
  2905.  
  2906.  
  2907.               Year  unsigned Year() const;
  2908.  
  2909.                     Returns the year.
  2910.  
  2911.  
  2912.  
  2913. ===========================================================================
  2914. BaseTime                                                            ltime.h
  2915. ===========================================================================
  2916.  
  2917.                     ┌────────────┐  ╔════════════╗  ┌────────────┐
  2918.                     │  Sortable  ├──╢  BaseTime  ╟──┤    Time    │
  2919.                     └────────────┘  ╚════════════╝  └────────────┘
  2920.  
  2921.                     BaseTime is an abstract class derived from Sortable
  2922.                     that provides basic time manipulation functions.
  2923.  
  2924.  
  2925.   Member functions  =======================================================
  2926.  
  2927.  
  2928.        constructor  BaseTime();                                   protected
  2929.  
  2930.                     Creates a BaseTime object with the current system time.
  2931.  
  2932.        constructor  BaseTime( const BaseTime& BT );               protected
  2933.  
  2934.                     Copy constructor.
  2935.  
  2936.        constructor  BaseTime( unsigned char H, unsigned char M = 0,
  2937.                               unsigned char S = 0, unsigned char HD = 0
  2938.                               );                                  protected
  2939.  
  2940.                     Creates a BaseTime object with the given hour, minutes,
  2941.                     seconds, and hundredths of seconds.
  2942.  
  2943.          hashValue  virtual hashValueType hashValue() const;
  2944.  
  2945.                     Returns the hash value of the BaseTime object. See
  2946.                     HashTable::hashValue for more details.
  2947.  
  2948.               hour  unsigned hour() const;
  2949.  
  2950.                     Returns the hour.
  2951.  
  2952.         hundredths  unsigned hundredths() const;
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.                                   - 51 -
  2959.  
  2960.  
  2961. BaseTime
  2962.  
  2963.  
  2964.  
  2965.                     Returns the hundredths of a second.
  2966.  
  2967.                isA  virtual classType isA() const = 0;
  2968.  
  2969.                     Pure virtual function for a derived class to return its
  2970.                     class ID.
  2971.  
  2972.            isEqual  virtual int isEqual( const Object& testTime ) const;
  2973.  
  2974.                     Returns 1  if this object equals testTime; otherwise
  2975.                     returns 0.
  2976.  
  2977.         isLessThan  virtual int isLessThan( const Object& testTime ) const;
  2978.  
  2979.                     Returns 1  if this object is less than testTime;
  2980.                     otherwise returns 0 .
  2981.  
  2982.             minute  unsigned minute() const;
  2983.  
  2984.                     Returns the minute.
  2985.  
  2986.             nameOf  virtual char *nameOf() const = 0;
  2987.  
  2988.                     Pure virtual function to be defined by derived classes
  2989.                     to return their object ID string.
  2990.  
  2991.            printOn  virtual void printOn( ostream& outStream ) const = 0;
  2992.  
  2993.   operator << is a  Pure virtual function to be defined in derived classes
  2994.  friend of Object.  to print the time object on the given stream. printOn
  2995.       See page 87.  is for internal use by the overloaded operator <<.
  2996.  
  2997.             second  unsigned second() const;
  2998.  
  2999.                     Returns the seconds.
  3000.  
  3001.            setHour  void setHour( unsigned char H );
  3002.  
  3003.                     Sets the hour to H.
  3004.  
  3005.      setHundredths  void setHundredths( unsigned char HD );
  3006.  
  3007.                     Sets the hundredths of a second to HD.
  3008.  
  3009.          setMinute  void  setMinute( unsigned char M );
  3010.  
  3011.                     Sets the minutes.
  3012.  
  3013.  
  3014.  
  3015.  
  3016.                                   - 52 -
  3017.  
  3018.  
  3019.                                                                    BaseTime
  3020.  
  3021.  
  3022.  
  3023.          setSecond  void  setSecond( unsigned char S );
  3024.  
  3025.                     Sets the seconds.
  3026.  
  3027.  
  3028.  
  3029. ===========================================================================
  3030. Btree                                                               btree.h
  3031. ===========================================================================
  3032.  
  3033.                     ┌────────────┐  ╔════════════╗
  3034.                     │ Collection ├──╢   Btree    ║
  3035.                     └────────────┘  ╚════════════╝
  3036.  
  3037.                     The class Btree, derived from Collection, implements
  3038.                     the B-tree, a popular data structure offering efficient
  3039.                     storage and retrieval with large, dynamic volumes of
  3040.                     data. (A detailed account of Turbo C++ development of
  3041.                     B-tree theory is beyond the scope of this manual: see
  3042.                     BTREE.CPP and D. E Knuth's The Art of Computer
  3043.                     Programming, Volume 3, 6.2.3.). Btree makes use of
  3044.                     several auxiliary, noncontainer friend classes: Node,
  3045.                     Item, InnerNode, and LeafNode (the last two being
  3046.                     derived from Node). You can study these in btree.h.
  3047.                     Here, we will just outline the members of the Btree
  3048.                     class, which should suffice for most applications.
  3049.  
  3050.  
  3051.   Member functions  =======================================================
  3052.  
  3053.  
  3054.                add  void add( Object& );
  3055.  
  3056.                     Add the given object to the B-tree.
  3057.  
  3058.        constructor  Btree( int ordern = 3 );
  3059.  
  3060.                     Creates a B-tree of order ordern (default order is 3).
  3061.  
  3062.        decrNofKeys  void decrNofKeys();                           protected
  3063.  
  3064.                     Decrements the itemsInContainer data member
  3065.  
  3066.             detach  void detach( Object& toDetach, DeleteType dt = NoDelete
  3067.                     );
  3068.  
  3069.  
  3070.  
  3071.  
  3072.  
  3073.  
  3074.                                   - 53 -
  3075.  
  3076.  
  3077. Btree
  3078.  
  3079.  
  3080.  
  3081.                     Removes the given object from the B-tree. The fate of
  3082.                     the removed object depends on the argument dt. See
  3083.                     TShouldDelete for details.
  3084.  
  3085.         findMember  virtual Object& findMember( const Object& toFind )
  3086.                     const;
  3087.  
  3088.                     Returns the given object if found, otherwise returns
  3089.                     NOOBJECT.
  3090.  
  3091.              flush  void flush( DeleteType dt = DefDelete );
  3092.  
  3093.                     Flushes (empties) the B-tree. The fate of the removed
  3094.                     objects depends on the argument dt. See TShouldDelete
  3095.                     for details.
  3096.  
  3097.          hasMember  virtual int hasMember( const Object& obj ) const;
  3098.  
  3099.                     Returns 1  if the given object is found in the B-tree,
  3100.                     otherwise returns 0.
  3101.  
  3102.          hashValue  virtual hashValueType hashValue() const;
  3103.  
  3104.                     Returns the hash value of this B-tree. See
  3105.                     HashTable::hashValue for more details.
  3106.  
  3107.              i_add  long i_add( const Object& obj );              protected
  3108.  
  3109.                     Adds the given object to the tree and returns the index
  3110.                     in the tree at which the object was inserted.
  3111.  
  3112.        incrNofKeys  void incrNofKeys();                           protected
  3113.  
  3114.                     Increments the itemsInContainer data member
  3115.  
  3116.       initIterator  virtual ContainerIterator& initIterator() const;
  3117.  
  3118.                     Creates an iterator for this B-tree.
  3119.  
  3120.                     See also: Container::initIterator
  3121.  
  3122.                isA  virtual classType isA() const;
  3123.  
  3124.                     Returns btreeClass, the Btree class ID
  3125.  
  3126.            isEqual  virtual int isEqual( const Object& testObject ) const;
  3127.  
  3128.                     Returns 1  if testObject is the same as this object.
  3129.  
  3130.  
  3131.  
  3132.                                   - 54 -
  3133.  
  3134.  
  3135.                                                                       Btree
  3136.  
  3137.  
  3138.  
  3139.             nameOf  virtual char *nameOf() const;
  3140.  
  3141.                     Returns "Btree", the Btree class ID string
  3142.  
  3143.        operator []  Object& operator[]( long i ) const;
  3144.  
  3145.                     Returns the root at index i
  3146.  
  3147.              order  int order();
  3148.  
  3149.                     Returns the order of the B-tree.
  3150.  
  3151.            printOn  virtual void printOn( ostream& outputStream ) const;
  3152.  
  3153.   operator << is a  Sends the formatted B-tree data to the given output
  3154.  friend of Object.  stream. printOn is for internal use by the overloaded
  3155.       See page 87.  operator <<.
  3156.  
  3157.               rank  long rank( const Object& obj ) const;
  3158.  
  3159.                     Returns the rank of the given object in the B-tree.
  3160.  
  3161.  
  3162.            Friends  =======================================================
  3163.  
  3164.                     Node, InnerNode, and LeafNode are friends of Btree.
  3165.  
  3166.  
  3167.  
  3168. ===========================================================================
  3169. BtreeIterator                                                       btree.h
  3170. ===========================================================================
  3171.  
  3172.                     ┌─────────────────┐  ╔══════════════════╗
  3173.                     │ContainerIterator├──╢  BtreeIterator   ║
  3174.                     └─────────────────┘  ╚══════════════════╝
  3175.  
  3176.                     The class BtreeIterator is derived from
  3177.                     ContainerIterator. Its members follow the same scheme
  3178.                     as those for the other container iterators.
  3179.  
  3180.  
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.  
  3187.  
  3188.  
  3189.  
  3190.                                   - 55 -
  3191.  
  3192.  
  3193. BtreeIterator
  3194.  
  3195.  
  3196.  
  3197.   Member functions  =======================================================
  3198.  
  3199.  
  3200.        constructor  BtreeIterator( const Btree& toIterate );
  3201.  
  3202.                     See ContainerIterator constructor
  3203.  
  3204.            current  virtual Object& current();
  3205.  
  3206.                     See ContainerIterator::current
  3207.  
  3208.        operator ++  virtual Object& operator ++();
  3209.                     virtual Object& operator ++( int );
  3210.  
  3211.                     See ContainerIterator::operator ++
  3212.  
  3213.       operator int  virtual operator int();
  3214.  
  3215.                     Conversion operator to test for end of iterator
  3216.                     position.
  3217.  
  3218.            restart  virtual void restart();
  3219.  
  3220.                     See ContainerIterator::restart
  3221.  
  3222.  
  3223.  
  3224.  
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.  
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.  
  3241.  
  3242.  
  3243.  
  3244.  
  3245.  
  3246.  
  3247.  
  3248.                                   - 56 -
  3249.  
  3250.  
  3251.                                                                  Collection
  3252.  
  3253.  
  3254.  
  3255. ===========================================================================
  3256. Collection                                                        collect.h
  3257. ===========================================================================
  3258.  
  3259.                                                      ┌─────────────┐
  3260.                                                    ┌─┤AbstractArray│
  3261.                                                    │ └─────────────┘
  3262.                                                    │ ┌─────────────┐
  3263.                                                    ├─┤  HashTable  │
  3264.                                                    │ └─────────────┘
  3265.                     ┌────────────┐  ╔════════════╗ │ ┌─────────────┐
  3266.                     │ Container  ├──╢ Collection ╟─┼─┤    List     │
  3267.                     └────────────┘  ╚════════════╝ │ └─────────────┘
  3268.                                                    │ ┌─────────────┐
  3269.                                                    ├─┤ DoubleList  │
  3270.                                                    │ └─────────────┘
  3271.                                                    │ ┌─────────────┐
  3272.                                                    ├─┤    Bag      │
  3273.                                                    │ └─────────────┘
  3274.                                                    │ ┌─────────────┐
  3275.                                                    └─┤    Btree    │
  3276.                                                      └─────────────┘
  3277.  
  3278.                     Collection is an abstract class derived from the
  3279.                     abstract class Container. This means that although
  3280.                     Collection is more specialized than Container, it still
  3281.                     cannot be used directly for creating useful objects but
  3282.                     exists only as a further stepping stone towards usable,
  3283.                     derived instance classes.
  3284.  
  3285.                     Collection inherits five pure virtual functions (flush,
  3286.                     initIterator, isA, nameOf and getItemsInContainer),
  3287.                     that simply await definitions down the road by derived
  3288.                     instance classes.
  3289.  
  3290.                     Collection extends the functionality of Container in
  3291.                     several areas by adding both virtual and pure virtual
  3292.                     member functions. The extra pure virtual functions are
  3293.                     add and detach. Instance classes ultimately derived
  3294.                     from Collection, therefore, will need to provide
  3295.                     appropriate member functions for adding and removing
  3296.                     elements.
  3297.  
  3298.                     The other (non-pure) virtual member functions added by
  3299.                     Collection are destroy, hasMember, and findMember. The
  3300.                     last two provide the key difference between Collection
  3301.                     and Container. A Collection-derived object can
  3302.                     determine if any given object is a member (with
  3303.  
  3304.  
  3305.  
  3306.                                   - 57 -
  3307.  
  3308.  
  3309. Collection
  3310.  
  3311.  
  3312.  
  3313.                     hasMember) and, by using an iterator, can locate a
  3314.                     member object within the collection (with findMember).
  3315.  
  3316.                     The offspring of Collection refine these access methods
  3317.                     in various ways, and add other functions. In most
  3318.                     applications, you will be dealing directly with a
  3319.                     particular derived class of Collection, chosen to match
  3320.                     your needs: sorted and unsorted arrays, hash tables,
  3321.                     bags, sets, dictionaries, and single and double lists.
  3322.                     However, it is useful to have a feel for how these
  3323.                     instance classes build up from abstract classes, and
  3324.                     why it is useful to have intermediate abstract classes.
  3325.  
  3326.  
  3327.   Member functions  =======================================================
  3328.  
  3329.  
  3330.                add  virtual void add( Object& o ) = 0;
  3331.  
  3332.                     Pure virtual function to be defined in derived classes
  3333.                     to add an object to a collection.
  3334.  
  3335.        constructor  Uses the Container base constructor.
  3336.  
  3337.            destroy  void destroy( const Object& o );
  3338.  
  3339.                     Removes an object from a Collection. Whether the object
  3340.                     itself is destroyed or not depends on the ownership
  3341.                     status of the collection. If the collection currently
  3342.                     owns the object, the object will be destroyed,
  3343.                     otherwise the object survives. destroy is implemented
  3344.                     with detach( o, DefDelete );
  3345.  
  3346.                     See also:   TShouldDelete::ownsElements
  3347.  
  3348.             detach  virtual void detach( Object& o, DeleteType dt =
  3349.                     NoDelete) = 0;
  3350.  
  3351.                     Pure virtual function to be defined in derived classes
  3352.                     to remove an object from a collection. The destruction
  3353.                     of the object depends both on the ownership status and
  3354.                     the value (Delete, NoDelete, or DefDelete) passed via
  3355.                     the dt argument.
  3356.  
  3357.                     See also:   destroy, TShouldDelete::ownsElements
  3358.  
  3359.         findMember  virtual Object& findMember( const Object& testObject )
  3360.                     const;
  3361.  
  3362.  
  3363.  
  3364.                                   - 58 -
  3365.  
  3366.  
  3367.                                                                  Collection
  3368.  
  3369.  
  3370.  
  3371.                     Returns the test object if it is in the collection,
  3372.                     otherwise returns NOOBJECT.
  3373.  
  3374.          hasMember  virtual int hasMember( const Object& o ) const;
  3375.  
  3376.                     Returns 1  if the collection contains the given object.
  3377.  
  3378.  
  3379.  
  3380. ===========================================================================
  3381. Container                                                         contain.h
  3382. ===========================================================================
  3383.  
  3384.                                  ┌────────────┐
  3385.                                ┌─┤ Collection │
  3386.                                │ └────────────┘
  3387. ┌────────────┐  ╔════════════╗ │ ┌────────────┐
  3388. │   Object   ├──╢ Container  ╟─┼─┤   Stack    │
  3389. └────────────┘  ╚════════════╝ │ └────────────┘
  3390.                                │ ┌────────────────────┐
  3391.                                ├─┤   PriorityQueue    │
  3392.                                │ └────────────────────┘
  3393.                                │
  3394.                                │ ┌────────────┐ ┌────────────┐ 
  3395.                                └─┤   Deque    ├─┤   Queue    │
  3396.                                  └────────────┘ └────────────┘
  3397.                                  
  3398.  
  3399.                     The abstract class Container, derived directly from
  3400.                     Object, is the base for all the container classes.
  3401.                     Container has a second pure virtual base class (not
  3402.                     shown) called TShouldDelete. Container provides the
  3403.                     following functionality:
  3404.  
  3405.                     1. A container can store objects of other classes,
  3406.                        known as elements or items. (The objects in a
  3407.                        container are sometimes called "members" of the
  3408.                        container, but this usage can lead to ambiguities in
  3409.                        C++.) A container can flush itself by removing all
  3410.                        its elements.
  3411.  
  3412.                     2. A container can determine the number of objects it
  3413.                        holds. Empty containers are allowed.
  3414.  
  3415.                     3. Container is also derived from TShouldDelete
  3416.                        (multiple inheritance), which lets you control the
  3417.                        ownership of a container's elements. By default, a
  3418.                        container owns its elements, meaning that it will
  3419.  
  3420.  
  3421.  
  3422.                                   - 59 -
  3423.  
  3424.  
  3425. Container
  3426.  
  3427.  
  3428.  
  3429.                        destroy them when its destructor is called or when
  3430.                        it is flushed.
  3431.  
  3432.                     4. A container can create external iterators, objects
  3433.                        of type ContainerIterator, which can be used to
  3434.                        traverse the container, element by element. With
  3435.                        external iterators, you need to handle the scanning
  3436.                        of the elements yourself. Other iterators, known as
  3437.                        internal iterators, are generated automatically by
  3438.                        certain member functions. These do their own loop
  3439.                        tests and can perform arbitrary actions on each
  3440.                        element (forEach). Member functions are also
  3441.                        available for scanning the container until a certain
  3442.                        condition is satisfied (firstThat, lastThat).
  3443.  
  3444.                     5. A container can test if it is equal to another
  3445.                        container.
  3446.  
  3447.                     6. A container can display its elements on streams in a
  3448.                        formatted way. A printOn function is provided from
  3449.                        which the usual overloaded << output operator can be
  3450.                        obtained.
  3451.  
  3452.                     Strictly speaking, some of the above member functions
  3453.                     are pure virtual functions that need to be defined in
  3454.                     derived classes. See Collection class for a more
  3455.                     detailed discussion.
  3456.  
  3457.                     Specialized containers are derived to two ways:
  3458.                     directly derived are the classes Stack, PriorityQueue,
  3459.                     and Deque (from which Queue is derived). Derived
  3460.                     indirectly via another abstract class, Collection, are
  3461.                     AbstractArray, HashTable, Bag, Btree, List, and
  3462.                     DoubleList.
  3463.  
  3464.   itemsInContainer  countType itemsInContainer;                   protected
  3465.  
  3466.                     Holds the current number of elements in the container.
  3467.  
  3468.                     See also: getItemsInContainer
  3469.  
  3470.  
  3471.   Member functions  =======================================================
  3472.  
  3473.  
  3474.        constructor  Container();
  3475.  
  3476.                     Creates an empty container.
  3477.  
  3478.  
  3479.  
  3480.                                   - 60 -
  3481.  
  3482.  
  3483.                                                                   Container
  3484.  
  3485.  
  3486.  
  3487.          firstThat  virtual Object& firstThat( condFuncType testFuncPtr,
  3488.                     void *paramList ) const;
  3489.  
  3490.                     Returns a reference to the first object in the
  3491.                     container that satisfies a given condition. You supply
  3492.                     a testFuncPtr that returns true for a certain
  3493.                     condition. You can pass arbitrary arguments via the
  3494.                     paramList argument. NOOBJECT is returned if no object
  3495.                     in the container meets the condition. Note that you are
  3496.                     not involved directly with iterators: firstThat and
  3497.                     lastThat create their own internal iterators, so you
  3498.                     can simply treat them as "search" functions.
  3499.  
  3500.                     See also:   lastThat, Object::firstThat
  3501.  
  3502.              flush  virtual void flush( DeleteType dt = DefDelete ) = 0;
  3503.  
  3504.                     A pure virtual function to be defined in derived
  3505.                     classes. Flushing means removing all the elements from
  3506.                     the container without destroying it. The value of dt
  3507.                     determines whether the elements themselves are
  3508.                     destroyed. By default, the ownership status of the
  3509.                     container determines their fate. You can also set dt to
  3510.                     Delete and NoDelete.
  3511.  
  3512.                     See also: TShouldDelete::ownsElements
  3513.  
  3514.            forEach  virtual void forEach( iterFuncType actionFuncPtr, void
  3515.                     *args );
  3516.  
  3517.                     forEach creates an internal iterator to execute the
  3518.                     given action function for each element in the
  3519.                     container. The args argument lets you pass arbitrary
  3520.                     data to the action function.
  3521.  
  3522. getItemsInContainer virtual countType getItemsInContainer() const = 0;
  3523.  
  3524.                     Pure virtual function to be defined by derived classes
  3525.                     to return the number of elements in a container.
  3526.  
  3527.          hashValue  virtual hashValueType hashValue() const = 0;
  3528.  
  3529.                     A pure virtual function to be defined by derived
  3530.                     classes to return the hash value of an object. See
  3531.                     HashTable::hashValue for more details.
  3532.  
  3533.       initIterator  virtual ContainerIterator& initIterator() const = 0;
  3534.  
  3535.  
  3536.  
  3537.  
  3538.                                   - 61 -
  3539.  
  3540.  
  3541. Container
  3542.  
  3543.  
  3544.  
  3545.                     Pure virtual function to be defined in derived classes
  3546.                     to initialize an external container iterator.
  3547.  
  3548.                isA  virtual classType isA() const = 0;
  3549.  
  3550.                     Pure virtual function to be defined in derived classes
  3551.                     to return their class ID.
  3552.  
  3553.            isEmpty  virtual int isEmpty() const = 0;
  3554.  
  3555.                     Pure virtual function to be defined in derived classes.
  3556.                     Returns 1  if a container has no elements; otherwise
  3557.                     returns 0.
  3558.  
  3559.            isEqual  virtual int isEqual( const Object& testObject ) const;
  3560.  
  3561.                     Returns 1  if the testObject is a container of the same
  3562.                     type and size as this container, and with the same
  3563.                     objects in the same order. Otherwise returns 0.
  3564.  
  3565.           lastThat  virtual Object& lastThat( condFuncType testFuncPtr,
  3566.                     void *paramList ) const;
  3567.  
  3568.                     Returns a reference to the last object in the container
  3569.                     that satisfies a given condition. You supply a
  3570.                     testFuncPtr that returns true for a certain condition.
  3571.                     You can pass arbitrary arguments via the paramList
  3572.                     argument. NOOBJECT is returned if no object in the
  3573.                     container meets the condition. Note that you are not
  3574.                     involved directly with iterators: firstThat and
  3575.                     lastThat create their own internal iterators, so you
  3576.                     can simply treat them as "search" functions.
  3577.  
  3578.                     See also:   firstThat, Object::firstThat
  3579.  
  3580.             nameOf  virtual char *nameOf() const = 0;
  3581.  
  3582.                     Pure virtual function to be defined by derived classes
  3583.                     to return their object type ID string (usually the
  3584.                     unique class name).
  3585.  
  3586.        printHeader  virtual void printHeader( ostream& outputStream )
  3587.                     const;
  3588.  
  3589.                     Sends a standard header for containers to the output
  3590.                     stream (called by printOn).
  3591.  
  3592.                     See also: printOn, printSeparator, printTrailer
  3593.  
  3594.  
  3595.  
  3596.                                   - 62 -
  3597.  
  3598.  
  3599.                                                                   Container
  3600.  
  3601.  
  3602.  
  3603.            printOn  virtual void printOn( ostream& outputStream ) const;
  3604.  
  3605.   operator << is a  Sends a formatted representation of the container to
  3606.  friend of Object.  the given output stream. printOn is for internal use by
  3607.       See page 87.  the overloaded operator <<.
  3608.  
  3609.                     See also: printHeader, printSeparator, printTrailer
  3610.  
  3611.     printSeparator  virtual void printSeparator( ostream& outputStream )
  3612.                     const;
  3613.  
  3614.                     Sends to the output stream a separator (comma) between
  3615.                     elements in a container (called by printOn).
  3616.  
  3617.                     See also: printOn, printHeader, printTrailer
  3618.  
  3619.       printTrailer  virtual void printTrailer( ostream& outputStream )
  3620.                     const;
  3621.  
  3622.                     Sends to the output stream a standard trailer (a
  3623.                     closing brace) for a container (called by printOn).
  3624.  
  3625.                     See also: printOn, printHeader, printSeparator
  3626.  
  3627.  
  3628.            Friends  =======================================================
  3629.  
  3630.                     ContainerIterator is a friend of Container.
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636.  
  3637.  
  3638.  
  3639.  
  3640.  
  3641.  
  3642.  
  3643.  
  3644.  
  3645.  
  3646.  
  3647.  
  3648.  
  3649.  
  3650.  
  3651.  
  3652.  
  3653.  
  3654.                                   - 63 -
  3655.  
  3656.  
  3657. ContainerIterator
  3658.  
  3659.  
  3660.  
  3661. ===========================================================================
  3662. ContainerIterator                                                 contain.h
  3663. ===========================================================================
  3664.  
  3665.                                           ┌──────────────────┐
  3666.                                         ┌─┤HashTableIterator │
  3667.                                         │ └──────────────────┘
  3668.                     ╔═════════════════╗ │ ┌──────────────────┐
  3669.                     ║ContainerIterator╟─┼─┤   ListIterator   │
  3670.                     ╚═════════════════╝ │ └──────────────────┘
  3671.                                         │ ┌──────────────────┐
  3672.                                         ├─┤DoubleListIterator│
  3673.                                         │ └──────────────────┘
  3674.                                         │ ┌──────────────────┐
  3675.                                         ├─┤  BtreeIterator   │
  3676.                                         │ └──────────────────┘
  3677.                                         │ ┌──────────────────┐
  3678.                                         └─┤  ArrayIterator   │
  3679.                                           └──────────────────┘
  3680.  
  3681.                     ContainerIterator is an abstract class declared as a
  3682.                     friend of Container. Container classes have
  3683.                     initIterator member functions that create
  3684.                     ContainerIterator-derived objects. These provide the
  3685.                     basic mechanisms for traversing the elements in a
  3686.                     container: incrementing through the container;
  3687.                     returning positional information; testing for
  3688.                     conditions, and so on. The member functions for
  3689.                     ContainerIterator are all pure virtual and are defined
  3690.                     in derived classes. See page 11 for more on the
  3691.                     ContainerIterator hierarchy.
  3692.  
  3693.  
  3694.   Member functions  =======================================================
  3695.  
  3696.  
  3697.            current  virtual Object& current() = 0;
  3698.  
  3699.                     Pure virtual function to be defined in derived classes
  3700.                     to return the current element. If the current element
  3701.                     is empty or invalid, NOOBJECT is returned.
  3702.  
  3703.       operator int  virtual operator int() = 0;
  3704.  
  3705.                     Pure virtual function to be defined by derived classes
  3706.                     to provide a conversion operator to test for end of
  3707.                     iteration condition.
  3708.  
  3709.  
  3710.  
  3711.  
  3712.                                   - 64 -
  3713.  
  3714.  
  3715.                                                           ContainerIterator
  3716.  
  3717.  
  3718.  
  3719.        operator ++  virtual Object& operator ++() = 0;
  3720.                     virtual Object& operator ++( int ) = 0;
  3721.  
  3722.                     Advances the iterator one position in the container.
  3723.                     The first version returns the object referred to before
  3724.                     incrementing; the second version returns the object
  3725.                     referred to after incrementing. The int argument is a
  3726.                     dummy used to distinguish the two operators (see the
  3727.                     section on Operator Overloading in the Programmer's
  3728.                     Guide).
  3729.  
  3730.            restart  virtual void restart() = 0;
  3731.  
  3732.                     Pure virtual function to be refined in derived classes
  3733.                     to set the current index of the iterator to the first
  3734.                     nonempty element in the container.
  3735.  
  3736.  
  3737.  
  3738. ===========================================================================
  3739. Date                                                                ldate.h
  3740. ===========================================================================
  3741.  
  3742.                     ┌────────────┐  ╔════════════╗
  3743.                     │  BaseDate  ├──╢    Date    ║
  3744.                     └────────────┘  ╚════════════╝
  3745.                     The Date instance class is a direct descendant of the
  3746.                     abstract class BaseDate, defining a printOn function.
  3747.                     You can vary Date for different national conventions
  3748.                     without disturbing BaseDate.
  3749.  
  3750.  
  3751.   Member functions  =======================================================
  3752.  
  3753.  
  3754.        constructor  Date();
  3755.  
  3756.                     Calls the BaseDate constructor to create a date object
  3757.                     with today's date.
  3758.  
  3759.        constructor  Date( unsigned char M, unsigned char D, unsigned Y );
  3760.  
  3761.                     Calls the BaseDate constructor to create a date object
  3762.                     with the given  date.
  3763.  
  3764.        constructor  Date( const Date& aDate );
  3765.  
  3766.  
  3767.  
  3768.  
  3769.  
  3770.                                   - 65 -
  3771.  
  3772.  
  3773. Date
  3774.  
  3775.  
  3776.  
  3777.                     Copy constructor.
  3778.  
  3779.                isA  virtual classType isA() const;
  3780.  
  3781.                     Returns dateClass, the Date class ID.
  3782.  
  3783.             nameOf  virtual char *nameOf() const;
  3784.  
  3785.                     Returns "Date", the Date class ID string.
  3786.  
  3787.            printOn  virtual void printOn( ostream& outputStream ) const;
  3788.  
  3789.   operator << is a  Sends a formatted date to the given output stream. The
  3790.  friend of Object.  format is full month name, day, year, for example
  3791.       See page 87.  January 1, 1990. printOn is really for internal use by
  3792.                     the overloaded operator <<.
  3793.  
  3794.  
  3795.  
  3796. ===========================================================================
  3797. Deque                                                               deque.h
  3798. ===========================================================================
  3799.  
  3800.                     ┌────────────┐  ╔════════════╗ ┌────────────┐
  3801.                     │ Container  ├──╢   Deque    ╟─┤   Queue    │
  3802.                     └────────────┘  ╚════════════╝ └────────────┘
  3803.  
  3804.                     The instance class Deque (pronounced "deck"), derived
  3805.                     from Container, implements a double-ended queue so it
  3806.                     is one of the sequence classes. Objects can be
  3807.                     examined, inserted, and removed at both the left and
  3808.                     the right ends but nowhere else. You can use the member
  3809.                     functions peekLeft and peekRight to examine the objects
  3810.                     currently at the left and the right ends. putLeft and
  3811.                     putRight insert objects at the ends. The getLeft and
  3812.                     getRight members also access the end objects but detach
  3813.                     them from the deque. The fate of the objects removed
  3814.                     from the deque is determined by the same ownership and
  3815.                     DeleteType considerations discussed in the
  3816.                     TShouldDelete class (recall that TShouldDelete is a
  3817.                     virtual base class for Container). Deque also acts as
  3818.                     the base class for Queue.
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.  
  3826.  
  3827.  
  3828.                                   - 66 -
  3829.  
  3830.  
  3831.                                                                       Deque
  3832.  
  3833.  
  3834.  
  3835.            Example  =======================================================
  3836.  
  3837.             Source   #include <deque.h>
  3838.                      #include <strng.h>
  3839.  
  3840.                      main()
  3841.                      {
  3842.                          Deque d;
  3843.                          String *s1 = new String("one");
  3844.                          String *s2 = new String("two");
  3845.                          String *s3 = new String("three");
  3846.                          String *s4 = new String("four");
  3847.  
  3848.                          // Populate the deque
  3849.                          d.putLeft(*s1);
  3850.                          d.putRight(*s2);
  3851.                          d.putLeft(*s3);
  3852.                          d.putRight(*s4);
  3853.  
  3854.                          // Print to cout
  3855.                          cout << "As a container:\n" << d << endl;
  3856.  
  3857.                          // Empty to cout
  3858.                          cout << "As a Deque:\n";
  3859.                          while (!d.isEmpty())
  3860.                          {
  3861.                              cout << d.getLeft() << endl;
  3862.                          }
  3863.  
  3864.                          // Should be empty
  3865.                          cout << "\nShould be empty:\n" << d;
  3866.                      }
  3867.  
  3868.             Output   As a container:
  3869.                      Deque { three,
  3870.                          one,
  3871.                          two,
  3872.                          four }
  3873.  
  3874.                      As a Deque:
  3875.                      three
  3876.                      one
  3877.                      two
  3878.                      four
  3879.  
  3880.                      Should be empty:
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.                                   - 67 -
  3887.  
  3888.  
  3889. Deque
  3890.  
  3891.  
  3892.  
  3893.                      Deque { }
  3894.  
  3895.  
  3896.   Member functions  =======================================================
  3897.  
  3898.  
  3899.              flush  virtual void flush( DeleteType dt = DefDefault );
  3900.  
  3901.                     Flushes (empties) the deque without destroying it. The
  3902.                     fate of any objects thus removed depends on the current
  3903.                     ownership status and the value of the dt argument.
  3904.  
  3905.                     See also: TShouldDelete::ownsElements
  3906.  
  3907. getItemsInContainer virtual countType getItemsInContainer() const;
  3908.  
  3909.                     Returns the number of items in the deque.
  3910.  
  3911.            getLeft  Object& getLeft();
  3912.  
  3913.                     Returns the object at the left end and removes it from
  3914.                     the deque. Returns NOOBJECT if the deque is empty.
  3915.  
  3916.                     See also: TShouldDelete class
  3917.  
  3918.           getRight  Object& getRight();
  3919.  
  3920.                     As for getLeft, except that the right end of the deque
  3921.                     is returned.
  3922.  
  3923.                     See also: getLeft
  3924.  
  3925.       initIterator  virtual ContainerIterator& initIterator() const;
  3926.  
  3927.                     Initializes an iterator for the deque.
  3928.  
  3929.                     See also: Container::initIterator
  3930.  
  3931.                isA  virtual classType isA() const;
  3932.  
  3933.                     Returns dequeClass, the Deque class ID.
  3934.  
  3935.            isEmpty  virtual int isEmpty() const;
  3936.  
  3937.                     Returns 1  if a container has no elements; otherwise
  3938.                     returns 0.
  3939.  
  3940.             nameOf  virtual char *nameOf() const;
  3941.  
  3942.  
  3943.  
  3944.                                   - 68 -
  3945.  
  3946.  
  3947.                                                                       Deque
  3948.  
  3949.  
  3950.  
  3951.                     Returns "Deque", the Deque class ID string.
  3952.  
  3953.           peekLeft  Object& peekLeft() const;
  3954.  
  3955.                     Returns the object at the left end (head) of the deque.
  3956.                     The object stays in the deque.
  3957.  
  3958.          peekRight  Object& peekRight()
  3959.  
  3960.                     Returns the object at the right end (tail) of the
  3961.                     deque. The object stays in the deque.
  3962.  
  3963.            putLeft  void putLeft( Object& obj );
  3964.  
  3965.                     Adds (pushes) the given object at the left end (head)
  3966.                     of the deque.
  3967.  
  3968.           putRight  void putRight(Object& obj)
  3969.  
  3970.                     Adds (pushes) the given object at the right end (tail)
  3971.                     of the deque.
  3972.  
  3973.  
  3974.  
  3975. ===========================================================================
  3976. Dictionary                                                           dict.h
  3977. ===========================================================================
  3978.  
  3979.                     ┌────────────┐  ╔════════════╗
  3980.                     │    Set     ├──╢ Dictionary ║
  3981.                     └────────────┘  ╚════════════╝
  3982.                     A dictionary is a special collection of Association
  3983.                     type objects. The instance class Dictionary is derived
  3984.                     from Collection via Bag and Set, implying that no
  3985.                     duplicate association objects are allowed in a
  3986.                     dictionary. Dictionary overrides the add function and
  3987.                     adds a lookup function to the members inherited from
  3988.                     Set. lookup allows you to retrieve the value object of
  3989.                     an association stored in the dictionary if you supply
  3990.                     the key.
  3991.  
  3992.  
  3993.   Member functions  =======================================================
  3994.  
  3995.  
  3996.                add  virtual void add( Object& assoc );
  3997.  
  3998.  
  3999.  
  4000.  
  4001.  
  4002.                                   - 69 -
  4003.  
  4004.  
  4005. Dictionary
  4006.  
  4007.  
  4008.  
  4009.                     Adds the given association (assoc) to the dictionary.
  4010.                     If the given argument is not of type Association, a
  4011.                     runtime error occurs.
  4012.  
  4013.        constructor  Dictionary( unsigned sz = DEFAULT_HASH_TABLE_SIZE );
  4014.  
  4015.                     Invokes the base Set constructor to create an empty
  4016.                     dictionary of size sz.
  4017.  
  4018.                isA  virtual classType isA() const;
  4019.  
  4020.                     Returns dictionaryClass, the Dictionary class ID.
  4021.  
  4022.             lookup  Association& lookup( const Object& toLookUp ) const;
  4023.  
  4024.                     Returns the association matching the toLookUp key. If
  4025.                     no match is found, NOOBJECT is returned.
  4026.  
  4027.             nameOf  virtual char *nameOf() const;
  4028.  
  4029.                     Returns "Dictionary", the Dictionary class ID string.
  4030.  
  4031.  
  4032.  
  4033. ===========================================================================
  4034. DoubleList                                                        dbllist.h
  4035. ===========================================================================
  4036.  
  4037.                     ┌────────────┐  ╔════════════╗
  4038.                     │ Collection ├──╢ DoubleList ║
  4039.                     └────────────┘  ╚════════════╝
  4040.  
  4041.                     The instance class DoubleList, derived from Collection,
  4042.                     implements the classical doubly-linked list data
  4043.                     structure (see D. E Knuth's The Art of Computer
  4044.                     Programming, Volume 1, 2.2.5). Briefly, each node
  4045.                     object of a doubly-linked list has two links, one
  4046.                     pointing to the next node and one pointing to the
  4047.                     previous node. The extreme nodes are called the head
  4048.                     and the tail. As with the Deque class, you can examine,
  4049.                     add, and remove objects at either end of the list.
  4050.  
  4051.  
  4052.  
  4053.  
  4054.  
  4055.  
  4056.  
  4057.  
  4058.  
  4059.  
  4060.                                   - 70 -
  4061.  
  4062.  
  4063.                                                                  DoubleList
  4064.  
  4065.  
  4066.  
  4067.   Member functions  =======================================================
  4068.  
  4069.  
  4070.                add  virtual void add( Object& toAdd );
  4071.  
  4072.                     Add the given object at the beginning of the list.
  4073.  
  4074.          addAtHead  void addAtHead( Object& toAdd );
  4075.  
  4076.                     Adds the given object at the beginning (head) of the
  4077.                     list.
  4078.  
  4079.          addAtTail  void addAtTail( Object& toAdd );
  4080.  
  4081.                     Adds the given object at the end (tail) the list.
  4082.  
  4083.        constructor  DoubleList();
  4084.  
  4085.                     Creates a new, empty doubly-linked list.
  4086.  
  4087.    destroyFromHead  void destroyFromHead( const Object& toDestroy );
  4088.  
  4089.                     Detaches the first occurrence of the given object
  4090.                     encountered by searching from the beginning of the
  4091.                     list. The object is destroyed only if it is owned by
  4092.                     the list.
  4093.  
  4094.    destroyFromTail  void destroyFromTail( const Object& toDestroy );
  4095.  
  4096.                     Detaches the first occurrence of the given object
  4097.                     encountered by searching from the tail of the list
  4098.                     towards the head. The object is destroyed only if it is
  4099.                     owned by the list.
  4100.  
  4101.             detach  virtual void detach( Object& toDetach, DeleteType dt =
  4102.                     NoDelete );
  4103.  
  4104.                     Calls detachFromHead( toDetach, dt);
  4105.  
  4106.     detachFromHead  void detachFromHead( const Object& toDetach, DeleteType
  4107.                     dt = NoDelete );
  4108.  
  4109.                     Removes the first occurrence of the given object
  4110.                     encountered by searching from the beginning of the
  4111.                     list. The dt argument determines if the detached object
  4112.                     is itself destroyed. See TShouldDelete for details.
  4113.  
  4114.  
  4115.  
  4116.  
  4117.  
  4118.                                   - 71 -
  4119.  
  4120.  
  4121. DoubleList
  4122.  
  4123.  
  4124.  
  4125.     detachFromTail  void detachFromTail( const Object& toDetach, DeleteType
  4126.                     dt = NoDelete );
  4127.  
  4128.                     Removes the first occurrence of the object starting at
  4129.                     the tail of the list and scanning towards the head. The
  4130.                     dt argument determines if the detached object is itself
  4131.                     destroyed. See TShouldDelete for details.
  4132.  
  4133.              flush  virtual void flush( DeleteType dt = DefDelete);
  4134.  
  4135.                     Flushes (empties) the list without destroying it. The
  4136.                     fate of the objects thus removed is determined by the
  4137.                     dt argument as explained at TShouldDelete. The default
  4138.                     value of dt means that the removed objects will be
  4139.                     destroyed only if the list owns these objects.
  4140.  
  4141.                     See also: TShouldDelete::ownsElements
  4142.  
  4143.       initIterator  virtual ContainerIterator& initIterator() const;
  4144.  
  4145.                     Creates and returns a forward (from head to tail)
  4146.                     iterator for the list.
  4147.  
  4148.                isA  virtual classType isA() const;
  4149.  
  4150.                     Returns doubleListClass, the DoubleList class ID.
  4151.  
  4152.             nameOf  virtual char *nameOf() const;
  4153.  
  4154.                     Returns "DoubleList", the DoubleList class ID string.
  4155.  
  4156.         peekAtHead  Object& peekAtHead() const;
  4157.  
  4158.                     Returns the object at the head of the list (without
  4159.                     removing it).
  4160.  
  4161.         peekAtTail  Object& peekAtTail() const;
  4162.  
  4163.                     Returns the object at the tail of the list (without
  4164.                     removing it).
  4165.  
  4166.  
  4167.  
  4168.  
  4169.  
  4170.  
  4171.  
  4172.  
  4173.  
  4174.  
  4175.  
  4176.                                   - 72 -
  4177.  
  4178.  
  4179.                                                                  DoubleList
  4180.  
  4181.  
  4182.  
  4183.            Friends  =======================================================
  4184.  
  4185.                     DoubleListIterator is a friend of DoubleList
  4186.  
  4187.  
  4188.  
  4189. ===========================================================================
  4190. DoubleListIterator                                                dbllist.h
  4191. ===========================================================================
  4192.  
  4193.                     ┌─────────────────┐  ╔══════════════════╗
  4194.                     │ContainerIterator├──╢DoubleListIterator║
  4195.                     └─────────────────┘  ╚══════════════════╝
  4196.                     DoubleListIterator, derived from ContainerIterator,
  4197.                     implements the special iterators for traversing
  4198.                     doubly-linked lists in either direction. This class
  4199.                     adds overloading of the pre- and postdecrement operator
  4200.                     - - to allow reverse iteration. For more details on
  4201.                     iterators, see ContainerIterator, and
  4202.                     DoubleList::initIterator.
  4203.  
  4204.  
  4205.   Member functions  =======================================================
  4206.  
  4207.  
  4208.        constructor  DoubleListIterator(const DoubleList& toIterate, int
  4209.                     atHead = 1);
  4210.  
  4211.                     Creates an iterator for the given list. The iterator
  4212.                     will begin at the head of the list if atHead is 1 ,
  4213.                     otherwise it starts at the tail.
  4214.  
  4215.            current  virtual Object& current();
  4216.  
  4217.                     Returns the object at the current index of the
  4218.                     iterator. If the current index exceeds the upper bound,
  4219.                     NOOBJECT is returned.
  4220.  
  4221.        operator ++  virtual Object& operator ++ ( int );
  4222.                     virtual Object& operator ++ ();
  4223.  
  4224.                     See ContainerIterator operator ++
  4225.  
  4226.       operator - -  Object& operator - - ( int );
  4227.                     Object& operator - - ();
  4228.  
  4229.  
  4230.  
  4231.  
  4232.  
  4233.  
  4234.                                   - 73 -
  4235.  
  4236.  
  4237. DoubleListIterator
  4238.  
  4239.  
  4240.  
  4241.                     Moves the iterator back one position in the list. The
  4242.                     object returned is either the current object
  4243.                     (postdecrement) or the object at the new position
  4244.                     (predecrement), or NOOBJECT if no valid object at the
  4245.                     relevant position. The first version gives
  4246.                     postdecrement, the second gives predecrement. The int
  4247.                     argument is a dummy serving only to distinguish the two
  4248.                     operators.
  4249.  
  4250.       operator int  virtual operator int();
  4251.  
  4252.                     Conversion operator to test for the end of an iteration
  4253.                     condition.
  4254.  
  4255.            restart  virtual void restart();
  4256.  
  4257.                     Moves the iterator back to its starting position at the
  4258.                     head of the list.
  4259.  
  4260.                     See also: DoubleListIterator constructor
  4261.  
  4262.  
  4263.  
  4264. ===========================================================================
  4265. Error                                                              object.h
  4266. ===========================================================================
  4267.  
  4268.                     ┌────────────┐  ╔════════════╗
  4269.                     │   Object   ├──╢   Error    ║
  4270.                     └────────────┘  ╚════════════╝
  4271.  
  4272.                     The class Error is a special instance class derived
  4273.                     from Object. There is just one instance of class Error,
  4274.                     namely theErrorObject. Pointing to this global object
  4275.                     is the static object pointer Object::ZERO. NOOBJECT is
  4276.                     defined as  *(Object::ZERO) in object.h. The operator
  4277.                     Object::operator new returns a pointer to
  4278.                     theErrorObject if an attempt to allocate an object
  4279.                     fails. You may test the return value of the new
  4280.                     operator against Object::ZERO to see whether the
  4281.                     allocation failed.
  4282.                     NOOBJECT is rather like a null pointer, but serves the
  4283.                     vital function of occupying empty slots in a container.
  4284.                     For example, when an Array object is created (not to be
  4285.                     confused with a traditional C array), each of its
  4286.                     elements will initially contain NOOBJECT.
  4287.  
  4288.  
  4289.  
  4290.  
  4291.  
  4292.                                   - 74 -
  4293.  
  4294.  
  4295.                                                                       Error
  4296.  
  4297.  
  4298.  
  4299.   Member functions  =======================================================
  4300.  
  4301.  
  4302.             delete  void operator delete(void *);
  4303.  
  4304.                     Invokes a runtime error if an attempt to delete the
  4305.                     Error object is detected.
  4306.  
  4307.                isA  virtual classtype isA() const;
  4308.  
  4309.                     Returns errorClass, the Error class ID.
  4310.  
  4311.            isEqual  virtual int isEqual( const Object& testObject const );
  4312.  
  4313.                     Returns 1 if the test object is the Error object.
  4314.  
  4315.             nameOf  virtual char *nameOf() const;
  4316.  
  4317.                     Returns the Error class ID string.
  4318.  
  4319.            printOn  virtual void printOn(ostream& outputStream ) const;
  4320.  
  4321.   operator << is a  Prints the string "Error\n" on the given stream.
  4322.  friend of Object.  printOn is for internal use by the overloaded operator
  4323.       See page 87.  <<.
  4324.  
  4325.  
  4326.  
  4327. ===========================================================================
  4328. HashTable                                                         hashtbl.h
  4329. ===========================================================================
  4330.  
  4331.                     ┌────────────┐  ╔════════════╗
  4332.                     │ Collection ├──╢ HashTable  ║
  4333.                     └────────────┘  ╚════════════╝
  4334.  
  4335.                     The instance class HashTable provides an implementation
  4336.                     of an unordered collection in which objects are added
  4337.                     and retrieved via a hashing function. A hash table
  4338.                     provides a fixed array with size slots (usually a prime
  4339.                     number), one for each possible hash value modulo size.
  4340.                     A hashing function computes the hash value for each
  4341.                     object (or a key part of that object) to be added, and
  4342.                     this determines the slot to which the new object is
  4343.                     assigned.
  4344.  
  4345.  
  4346.  
  4347.  
  4348.  
  4349.  
  4350.                                   - 75 -
  4351.  
  4352.  
  4353. HashTable
  4354.  
  4355.  
  4356.  
  4357.                     For each containable object of class X, the member
  4358.                     function X::HashValue returns a value (of type
  4359.                     hashValueType) between 0 and 65535, which is as
  4360.                     "unique" as possible. This "raw" hash value is reduced
  4361.                     modulo size. We'll use the term hash value to refer to
  4362.                     this reduced value in the range 0 to size - 1. This
  4363.                     hash value serves as an index into the hash table. The
  4364.                     internal organization of the table is hidden, but it
  4365.                     may help you to consider the slots as pointers to
  4366.                     lists.
  4367.  
  4368.                     It should be clear that if you want to store more than
  4369.                     size objects, the hash value cannot be unique for each
  4370.                     object. So two cases arise when an object is added: if
  4371.                     the slot is empty, a new list is assigned to the slot
  4372.                     and the object is stored in the list; if the slot is
  4373.                     already occupied by an object with the same hash value
  4374.                     (known as a collision), the new object is stored in the
  4375.                     existing list attached to the slot. When it comes to
  4376.                     locating an object, the hashing function computes its
  4377.                     hash value to access the appropriate slot. If the slot
  4378.                     is empty, NOOBJECT is returned, otherwise a
  4379.                     List::findMember call locates the object.
  4380.  
  4381.                     Choosing the best HashValue function and table size is
  4382.                     a delicate compromise between avoiding too many
  4383.                     collisions and taking up too much memory. (Other
  4384.                     hashing techniques are available, but the modulo prime
  4385.                     method is the most common. For more on hash table
  4386.                     theory, see D. E. Knuth's The Art of Computer
  4387.                     Programming, Volume 3, 6.4.). Hashing is widely used by
  4388.                     compilers to maintain symbol tables.
  4389.  
  4390.  
  4391.   Member functions  =======================================================
  4392.  
  4393.  
  4394.                add  virtual void add( Object& objectToAdd );
  4395.  
  4396.                     Adds the given object to the hash table.
  4397.  
  4398.        constructor  HashTable( sizeType aPrime = DEFAULT_HASH_TABLE_SIZE );
  4399.  
  4400.                     Creates an empty table. The aPrime argument is a prime
  4401.                     number used in the hashing function (the default is
  4402.                     defined in resource.h).
  4403.  
  4404.             detach
  4405.  
  4406.  
  4407.  
  4408.                                   - 76 -
  4409.  
  4410.  
  4411.                                                                   HashTable
  4412.  
  4413.  
  4414.  
  4415.                     virtual void detach( Object& objectToDetach, DeleteType
  4416.                     dt = NoDelete );
  4417.  
  4418.                     Removes the given object from the hash table. Whether
  4419.                     the object itself is destroyed or not depends on the dt
  4420.                     argument, as explained in TShouldDelete::ownsElements.
  4421.  
  4422.         findMember  virtual Object& findMember( const Object& testObject )
  4423.                     const;
  4424.  
  4425.                     Returns the target object if found, otherwise returns
  4426.                     NOOBJECT.
  4427.  
  4428.              flush  virtual void flush( DeleteType dt = DefDelete );
  4429.  
  4430.                     Removes all the elements from the table without
  4431.                     destroying it. The value of dt determines whether the
  4432.                     elements themselves are destroyed. By default (dt =
  4433.                     DefDelete), the ownership status of the table
  4434.                     determines the fate of all its elements, as explained
  4435.                     in TShouldDelete::ownsElements. You can set dt to
  4436.                     Delete to force destruction of the flushed elements
  4437.                     regardless of ownership. If dt is set to NoDelete, the
  4438.                     flushed elements will survive regardless of ownership.
  4439.  
  4440.                     See also: TShouldDelete::ownsElements
  4441.  
  4442.          hashValue  virtual hashValueType hashValue() const;
  4443.  
  4444.                     Returns the raw hash value of this table. This must not
  4445.                     be confused with the hash values calculated by the hash
  4446.                     table for each of the objects it stores. When an object
  4447.                     x of class X is added or retrieved from a hash table h,
  4448.                     the raw hash value used is x.hashValue(). The true hash
  4449.                     value (usually modulo size) is obtained from the hash
  4450.                     table object via h.getHashValue( x ). Only classes with
  4451.                     a proper hashValue member function can provide objects
  4452.                     for storage in a hash table. All standard Object-
  4453.                     derived classes in the library have meaningful hashing
  4454.                     functions provided. For example, BaseDate::hashValue
  4455.                     (unless overridden) returns the value YY + MM + DD from
  4456.                     which the (private) member function
  4457.                     HashTable::getHashValue computes a hash value (using
  4458.                     mod size). It is this value that governs the hash
  4459.                     table's add, findMember, and detach operations.
  4460.  
  4461.       initIterator  virtual ContainerIterator& initIterator() const;
  4462.  
  4463.  
  4464.  
  4465.  
  4466.                                   - 77 -
  4467.  
  4468.  
  4469. HashTable
  4470.  
  4471.  
  4472.  
  4473.                     Creates and returns an iterator for the hash table. See
  4474.                     Container::initIterator for more details.
  4475.  
  4476.                isA  virtual classType isA() const;
  4477.  
  4478.                     Returns hashTableClass, the HashTable class ID.
  4479.  
  4480.             nameOf  virtual char *nameOf() const;
  4481.  
  4482.                     Returns "HashTable", the HashTable class ID string.
  4483.  
  4484.  
  4485.            Friends  =======================================================
  4486.  
  4487.                     HashTableIterator is a friend of HashTable
  4488.  
  4489.  
  4490.  
  4491. ===========================================================================
  4492. HashTableIterator                                                 hashtbl.h
  4493. ===========================================================================
  4494.  
  4495.                     ┌─────────────────┐  ╔══════════════════╗
  4496.                     │ContainerIterator├──╢HashTableIterator ║
  4497.                     └─────────────────┘  ╚══════════════════╝
  4498.  
  4499.                     HashTableIterator is an instance class providing
  4500.                     iterator functions for HashTable objects. Since hash
  4501.                     values are stored in an array, hash table iterators use
  4502.                     the array iterator mechanism. See ContainerIterator for
  4503.                     a detailed discussion of iterators.
  4504.  
  4505.  
  4506.   Member functions  =======================================================
  4507.  
  4508.  
  4509.        constructor  HashTableIterator( const Array& toIterate );
  4510.  
  4511.                     See ContainerIterator constructor
  4512.  
  4513.            current  virtual operator Object& current();
  4514.  
  4515.                     See ContainerIterator::current
  4516.  
  4517.       operator int  virtual operator int();
  4518.  
  4519.                     Conversion operator to test for end of iterator
  4520.                     position.
  4521.  
  4522.  
  4523.  
  4524.                                   - 78 -
  4525.  
  4526.  
  4527.                                                           HashTableIterator
  4528.  
  4529.  
  4530.  
  4531.        operator ++  virtual Object& operator ++ ( int );
  4532.                     virtual Object& operator ++ ();
  4533.  
  4534.                     See ContainerIterator::operator ++
  4535.  
  4536.            restart  virtual void restart()
  4537.  
  4538.                     See ContainerIterator::restart
  4539.  
  4540.  
  4541.  
  4542. ===========================================================================
  4543. List                                                                 list.h
  4544. ===========================================================================
  4545.  
  4546.                     ┌────────────┐  ╔════════════╗
  4547.                     │ Collection ├──╢    List    ║
  4548.                     └────────────┘  ╚════════════╝
  4549.  
  4550.                     The instance class List, derived from Collection,
  4551.                     implements a linear, linked list. Lists are unordered
  4552.                     collections in which objects are linked in one
  4553.                     direction only to form a chain. You can usually add
  4554.                     objects only at the start of a list but any object can
  4555.                     be removed from a list. You can traverse a list (from
  4556.                     head to tail) with an iterator to access the objects
  4557.                     sequentially. List has an internal private class
  4558.                     ListElement providing memory management and other
  4559.                     functions for the pairs of pointers (to object and to
  4560.                     next element) that constitute the elements of a List
  4561.                     object. (For more on list theory, see Sedgwick's
  4562.                     Algorithms and Knuth's The Art of Computer Programming,
  4563.                     Volume 1, 2.2).
  4564.  
  4565.   Member functions  =======================================================
  4566.  
  4567.  
  4568.                add  void add( Object& toAdd );
  4569.  
  4570.                     Adds the given object at the head of the list. The
  4571.                     added object becomes the new head.
  4572.  
  4573.        constructor  List();
  4574.  
  4575.                     Creates an empty list.
  4576.  
  4577.             detach
  4578.  
  4579.  
  4580.  
  4581.  
  4582.                                   - 79 -
  4583.  
  4584.  
  4585. List
  4586.  
  4587.  
  4588.  
  4589.                     virtual void detach( Object& toDetach, DeleteType dt =
  4590.                     NoDelete );
  4591.  
  4592.                     Removes the given object from the list. Whether the
  4593.                     object itself is destroyed or not depends on the dt
  4594.                     argument, as explained in TShouldDelete::ownsElements.
  4595.  
  4596.              flush  virtual void flush( DeleteType dt = DefDelete );
  4597.  
  4598.                     Removes all the objects from the list without
  4599.                     destroying it. The value of dt determines whether the
  4600.                     objects themselves are destroyed. By default (dt =
  4601.                     DefDelete), the ownership status of the list determines
  4602.                     the fate of its elements, as explained in
  4603.                     TShouldDelete::ownsElements. You can set dt to Delete
  4604.                     to force destruction of the flushed objects regardless
  4605.                     of ownership. If dt is set to NoDelete, the flushed
  4606.                     objects will survive regardless of ownership.
  4607.  
  4608.                     See also: TShouldDelete::ownsElements
  4609.  
  4610.          hashValue  virtual hashValueType hashValue() const;
  4611.  
  4612.                     Returns the hash value of this list. See
  4613.                     HashTable::hashValue for more details.
  4614.  
  4615.       initIterator  virtual ContainerIterator& initIterator() const;
  4616.  
  4617.                     See Container::initIterator
  4618.  
  4619.                isA  virtual classType isA() const;
  4620.  
  4621.                     Returns listClass the List class ID.
  4622.  
  4623.             nameOf  virtual char *nameOf() const;
  4624.  
  4625.                     Returns "List", the List class ID string.
  4626.  
  4627.           peekHead  Object& peekHead() const;
  4628.  
  4629.                     Returns the object at the head of the list.
  4630.  
  4631.  
  4632.            Friends  =======================================================
  4633.  
  4634.                     ListIterator is a friend of List and ListElement.
  4635.  
  4636.  
  4637.  
  4638.  
  4639.  
  4640.                                   - 80 -
  4641.  
  4642.  
  4643.                                                                ListIterator
  4644.  
  4645.  
  4646.  
  4647. ===========================================================================
  4648. ListIterator                                                         list.h
  4649. ===========================================================================
  4650.  
  4651.                     ┌─────────────────┐  ╔══════════════════╗
  4652.                     │ContainerIterator├──╢   ListIterator   ║
  4653.                     └─────────────────┘  ╚══════════════════╝
  4654.  
  4655.                     ListIterator is an instance class derived from
  4656.                     ContainerIterator providing iterator functions for List
  4657.                     objects. See ContainerIterator for a discussion of
  4658.                     iterators.
  4659.  
  4660.  
  4661.   Member functions  =======================================================
  4662.  
  4663.  
  4664.        constructor  ListIterator( const List& toIterate );
  4665.  
  4666.                     Creates an iterator for the given list. The starting
  4667.                     and current elements are set to the first element of
  4668.                     the list. See ContainerIterator constructor for
  4669.                     details.
  4670.  
  4671.            current  virtual Object& current();
  4672.  
  4673.                     See ContainerIterator::current
  4674.  
  4675.        operator ++  virtual Object& operator ++ ( int );
  4676.                     virtual Object& operator ++ ();
  4677.  
  4678.                     See ContainerIterator::operator ++
  4679.  
  4680.       operator int  virtual operator int();
  4681.  
  4682.                     Conversion operator to test for end of iterator
  4683.                     position.
  4684.  
  4685.  
  4686.            restart  virtual void restart()
  4687.  
  4688.                     See ContainerIterator::restart
  4689.  
  4690.  
  4691.  
  4692.  
  4693.  
  4694.  
  4695.  
  4696.  
  4697.  
  4698.                                   - 81 -
  4699.  
  4700.  
  4701. MemBlocks
  4702.  
  4703.  
  4704.  
  4705. ===========================================================================
  4706. MemBlocks                                                          memmgr.h
  4707. ===========================================================================
  4708.  
  4709.                     ╔════════════╗
  4710.                     ║ MemBlocks  ╟
  4711.                     ╚════════════╝
  4712.  
  4713.                     The classes MemBlocks and MemStack in memmgr.h offer
  4714.                     specialized memory management not only for the
  4715.                     container classes but for other applications. Detailed
  4716.                     knowledge of their operations is not needed for normal
  4717.                     container applications. If you are planning your own
  4718.                     advanced memory management schemes, you should first
  4719.                     study memmgr.h and MEMMGR.CPP.
  4720.  
  4721.                     MemBlocks is a noncontainer, instance class, providing
  4722.                     fixed-block memory allocations. Large, dynamic lists
  4723.                     and trees need to allocate and free their node blocks
  4724.                     as quickly as possible. MemBlocks offers more efficient
  4725.                     memory management than the standard heap manager for
  4726.                     this kind of operation. The MemBlock constructor takes
  4727.                     two arguments: block size and number of blocks. These
  4728.                     determine the size of the internal blocks that are
  4729.                     allocated as needed using the normal run-time library
  4730.                     allocation functions. A free list of blocks is
  4731.                     maintained and the internal blocks are not released
  4732.                     until the MemBlock object is destroyed. The following
  4733.                     example illustrates the use of MemBlocks with a
  4734.                     simplified Node class:
  4735.  
  4736.                      class Node
  4737.                      {
  4738.                        Node *next;
  4739.                        Object *obj;
  4740.                        static MemBlocks memBlocks;
  4741.                        void *operator new( size_t sz ) { return
  4742.                      memBlocks.allocate ( sz); }
  4743.                        void operator delete( void * blk ) { memBlocks.free
  4744.                      ( blk ); }
  4745.                        ...
  4746.                      };
  4747.  
  4748.                     CAUTION: If you derive a class from a class that does
  4749.                     its own memory management as in the  Node example
  4750.                     above, then either the derived class must be the same
  4751.                     size as the base class or you must override the new and
  4752.                     delete operators.
  4753.  
  4754.  
  4755.  
  4756.                                   - 82 -
  4757.  
  4758.  
  4759.                                                                   MemBlocks
  4760.  
  4761.  
  4762.  
  4763.                     See also: MemStack class.
  4764.  
  4765.           allocate  void allocate( size_t sz, unsigned blks = 100 );
  4766.  
  4767.                     Allocates blks blocks each of size sz
  4768.  
  4769.               free  void free( void * ptr );
  4770.  
  4771.                     Frees the memory blocks at ptr.
  4772.  
  4773.  
  4774.  
  4775. ===========================================================================
  4776. MemStack                                                           memmgr.h
  4777. ===========================================================================
  4778.  
  4779.                     ╔════════════╗
  4780.                     ║  MemStack  ║
  4781.                     ╚════════════╝
  4782.  
  4783.                     MemStack is a noncontainer, instance class, providing
  4784.                     fast mark-and-release style memory management. Although
  4785.                     used internally by various container classes, MemStack
  4786.                     is also available for general use. Memory allocations
  4787.                     and deallocations are extremely fast since they
  4788.                     "popped" and "pushed" on a stack of available blocks.
  4789.                     Marking and releasing blocks is handled by objects of a
  4790.                     helper marker class. When a marker is created it
  4791.                     records the current location in the memory stack; when
  4792.                     a marker is destroyed, the stack is returned to its
  4793.                     original state, freeing any allocations made since the
  4794.                     marker was created. For example:
  4795.  
  4796.                      MemStack symbols;
  4797.  
  4798.                      void handleLocals()
  4799.                      {
  4800.                        Marker locals( symbols );       // marks current
  4801.                      state of symbols
  4802.                        Sym *symbol1 = new(symbols)Sym; // add a Sym to the
  4803.                      table
  4804.                        Sym *symbol2 = new(symbols)Sym; // and another
  4805.                      }
  4806.  
  4807.                     When the function exits, the Marker destructor releases
  4808.                     the memory allocated by the new(symbols) calls made in
  4809.                     handleLocal and restores the memory stack.
  4810.  
  4811.  
  4812.  
  4813.  
  4814.                                   - 83 -
  4815.  
  4816.  
  4817. Object
  4818.  
  4819.  
  4820.  
  4821.                     See also: MemBlocks
  4822.  
  4823.  
  4824.  
  4825. ===========================================================================
  4826. Object                                                             object.h
  4827. ===========================================================================
  4828.  
  4829.                                      ┌────────────┐
  4830.                                    ┌─┤   Error    │
  4831.                                    │ └────────────┘
  4832.                     ╔════════════╗ │ ┌────────────┐
  4833.                     ║   Object   ╟─┼─┤  Sortable  │
  4834.                     ╚════════════╝ │ └────────────┘
  4835.                                    │ ┌────────────┐
  4836.                                    ├─┤Association │
  4837.                                    │ └────────────┘
  4838.                                    │ ┌────────────┐
  4839.                                    └─┤ Container  │
  4840.                                      └────────────┘
  4841.  
  4842.                     Object is an abstract class providing the primordial
  4843.                     base for the whole Object-based container hierarchy
  4844.                     (with the exception of the iterator classes). The
  4845.                     member functions provide the basic essentials for all
  4846.                     derived classes and the objects they contain. Object
  4847.                     has four immediate children: Error, Sortable,
  4848.                     Association, and Container.
  4849.  
  4850.  
  4851.        Data member  =======================================================
  4852.  
  4853.  
  4854.               ZERO  static Object *ZERO;
  4855.  
  4856.                     A static pointer to the unique instance of class Error.
  4857.                     ZERO is used to define NOOBJECT.
  4858.  
  4859.                     See also:   Error class
  4860.  
  4861.  
  4862.   Member functions  =======================================================
  4863.  
  4864.  
  4865.       constructors  Object();
  4866.                     Object( Object& obj );
  4867.  
  4868.                     Creates or copies an object.
  4869.  
  4870.  
  4871.  
  4872.                                   - 84 -
  4873.  
  4874.  
  4875.                                                                      Object
  4876.  
  4877.  
  4878.  
  4879.          firstThat  virtual Object& firstThat( condFuncType testFuncPtr,
  4880.                     void *paramList ) const;
  4881.  
  4882.                     Returns *this if the object satisfies the condition
  4883.                     specified by the BOOLEAN testFunc function, otherwise
  4884.                     NOOBJECT is returned. You can pass arbitrary arguments
  4885.                     via the paramList argument. Note that firstThat,
  4886.                     lastThat, and forEach work for all Object-derived
  4887.                     objects, both container and non-container objects,
  4888.                     whether they are in containers or not. With container
  4889.                     objects, you can get iteration through the contained
  4890.                     objects. When used with objects outside containers, the
  4891.                     three functions act only on the calling object, so
  4892.                     firstThat and lastThat are equivalent. condFuncType is
  4893.                     defined in clstypes.h as
  4894.  
  4895.                     #typdef int ( *condFuncType )( const class Object&,
  4896.                     void *);
  4897.  
  4898.                     firstThat calls ( *testFuncPtr )( *this, paramList ).
  4899.                     If 1 is returned, firstThat returns (Object &) *this,
  4900.                     otherwise NOOBJECT is returned.
  4901.  
  4902.                     See also:   Container::firstThat
  4903.  
  4904.            forEach  virtual void forEach( iterFuncType actionFuncPtr, void
  4905.                     *args );
  4906.  
  4907.                     forEach executes the given action function on *this.
  4908.                     The args argument lets you pass arbitrary data to the
  4909.                     action function.
  4910.  
  4911.                     See also:   firstThat
  4912.  
  4913.          hashValue  virtual hashValueType hashValue() const = 0;
  4914.  
  4915.                     A pure virtual function to be defined by derived
  4916.                     classes to return the hash value of an object. See
  4917.                     HashTable::hashValue for more details.
  4918.  
  4919.                isA  virtual classType isA() const = 0;
  4920.  
  4921.                     Pure virtual function for derived classes to return a
  4922.                     class ID.
  4923.  
  4924.      isAssociation  virtual int isAssociation() const;
  4925.  
  4926.  
  4927.  
  4928.  
  4929.  
  4930.                                   - 85 -
  4931.  
  4932.  
  4933. Object
  4934.  
  4935.  
  4936.  
  4937.                     Returns 1  if the calling object is part of an
  4938.                     Association object, otherwise returns 0. Must be
  4939.                     overridden in classes providing associations.
  4940.  
  4941.                     See also: Association class.
  4942.  
  4943.            isEqual  virtual int isEqual( const Object& testObject ) const =
  4944.                     0;
  4945.  
  4946.                     Pure virtual function to be defined in derived classes
  4947.                     to test for equality between testObject and the calling
  4948.                     object (assumed to be of the same type). isEqual is
  4949.                     really for internal use by the operator == which first
  4950.                     applies isA to see if the compared objects are of the
  4951.                     same type. If they are, == then uses isEqual.
  4952.  
  4953.                     See also: operator ==
  4954.  
  4955.        isSorttable  virtual int isSortable() const;
  4956.  
  4957.                     Returns 1  if the calling object can be sorted; that
  4958.                     is, if the class Sortable is an ancestor. Otherwise
  4959.                     returns 0. Object::isSortable returns 0. Sortable
  4960.                     classes must override isSortable to return true.
  4961.  
  4962.                     See also: Sortable class
  4963.  
  4964.           lastThat  virtual Object& lastThat( condFuncType testFuncPtr,
  4965.                     void *paramList ) const;
  4966.  
  4967.                     Returns *this if the object satisfies the condition
  4968.                     specified by the BOOLEAN testFuncPtr function,
  4969.                     otherwise NOOBJECT is returned. You can pass arbitrary
  4970.                     arguments via the paramList argument. Note that
  4971.                     firstThat, lastThat, and forEach work for all Object-
  4972.                     derived objects, both container and non-container
  4973.                     objects, whether they are in containers or not. With
  4974.                     container objects, you get iteration through the
  4975.                     contained objects. When used with objects outside
  4976.                     containers, the three functions act only on the calling
  4977.                     object, so firstThat and lastThat are equivalent.
  4978.  
  4979.                     See also:   firstThat, Container::lastThat
  4980.  
  4981.             nameOf  virtual char *nameOf() const = 0;
  4982.  
  4983.                     Pure virtual function to be defined by derived classes
  4984.                     to return their object ID string.
  4985.  
  4986.  
  4987.  
  4988.                                   - 86 -
  4989.  
  4990.  
  4991.                                                                      Object
  4992.  
  4993.  
  4994.  
  4995.                new  void *operator new( size_t size );
  4996.  
  4997.                     Overrides the C++ operator new. Allocates size bytes
  4998.                     for an object. Returns ZERO if the allocation fails,
  4999.                     otherwise returns a pointer to the new object.
  5000.  
  5001.            printOn  virtual void printOn( ostream& outputStream ) const =
  5002.                     0;
  5003.  
  5004.                     Pure virtual function to be defined in derived classes
  5005.                     to provide formatted output of objects on the given
  5006.                     output stream. printOn is really for internal use by
  5007.                     the overloaded operator <<.
  5008.  
  5009.                     See also: operator <<
  5010.  
  5011.           ptrToRef  static Object ptrToRef( Object *p );
  5012.  
  5013.                     Returns *ZERO is p is 0, else returns *p
  5014.  
  5015.  
  5016.            Friends  =======================================================
  5017.  
  5018.        operator <<  ostream& operator <<( ostream& outputStream, const
  5019.                     Object& anObject );
  5020.  
  5021.                     Uses printOn to send a formatted representation of
  5022.                     anObject to the given output stream. The stream is
  5023.                     returned, allowing the usual chaining of the <<
  5024.                     operator.
  5025.  
  5026.                     operator << is a friend of Object.
  5027.  
  5028.  
  5029.  Related functions  =======================================================
  5030.  
  5031.                     The following overloaded operators are related to
  5032.                     Object but are not member functions:
  5033.  
  5034.        operator ==  int operator ==( const Object& test1, const Object&
  5035.                     test2 );
  5036.  
  5037.                     Returns 1  if the two objects are equal, otherwise
  5038.                     returns 0. Equal means that isA and isEqual each return
  5039.                     the same values for the two objects.
  5040.  
  5041.  
  5042.  
  5043.  
  5044.  
  5045.  
  5046.                                   - 87 -
  5047.  
  5048.  
  5049. Object
  5050.  
  5051.  
  5052.  
  5053.                     Note that for sortable objects (derived from the class
  5054.                     Sortable) there are also overloaded nonmember operators
  5055.                     <, >, <=, and >=.
  5056.  
  5057.                     See also: Object::isA, Object::isEqual, operator !=,
  5058.                     Sortable class.
  5059.  
  5060.        operator !=  int operator !=( const Object& test1, const Object&
  5061.                     test2 );
  5062.  
  5063.                     Returns 1  if the two objects are unequal, otherwise
  5064.                     returns 0. Unequal means that either isA or isEqual
  5065.                     each return the different values for the two objects.
  5066.  
  5067.                     See also: Object::isA, Object::isEqual, operator ==
  5068.  
  5069.  
  5070.  
  5071. ===========================================================================
  5072. PriorityQueue                                                    priortyq.h
  5073. ===========================================================================
  5074.  
  5075.                     ┌────────────┐  ╔════════════════════╗
  5076.                     │ Container  ├──╢   PriorityQueue    ║
  5077.                     └────────────┘  ╚════════════════════╝
  5078.  
  5079.                     The instance class Priority Queue, derived from
  5080.                     Container, implements the traditional priority queue
  5081.                     data structure. The objects in a priority queue must be
  5082.                     sortable (see Sortable class for details). A priority
  5083.                     queue is either a GIFO (greatest-in-first-out) or SIFO
  5084.                     (smallest-in-first-out) container widely used in
  5085.                     scheduling algorithms. The difference really depends on
  5086.                     your ordering definition. In explaining this
  5087.                     implementation, we'll assume a GIFO. You can picture
  5088.                     sortable objects being added at the right, but each
  5089.                     extraction from the left gives the "greatest" object in
  5090.                     the queue. (For applications where you need to extract
  5091.                     the smallest item, you need to adjust your definition
  5092.                     of "less than.") A detailed discussion of priority
  5093.                     queues can be found in Knuth's The Art of Computer
  5094.                     Programming, Volume 3, 5.2.3.
  5095.  
  5096.                     The member function put adds objects to the queue;
  5097.                     peekLeft lets you examine the largest element in the
  5098.                     queue; get removes and returns the largest element; you
  5099.                     can also detach this item with detachLeft without
  5100.  
  5101.  
  5102.  
  5103.  
  5104.                                   - 88 -
  5105.  
  5106.  
  5107.                                                               PriorityQueue
  5108.  
  5109.  
  5110.  
  5111.                     "getting" it. PriorityQueue is implemented internally
  5112.                     using a private Btree object called tree.
  5113.  
  5114.  
  5115.   Member functions  =======================================================
  5116.  
  5117.  
  5118.         detachLeft  void detachLeft( Container::DeleteType dt =
  5119.                     Container::DefDelete );
  5120.  
  5121.                     Removes the smallest object from the priority queue.
  5122.                     Whether this object is destroyed or not depends on the
  5123.                     value of dt as explained in
  5124.                     TShouldDelete::ownsElements.
  5125.  
  5126.              flush  void flush( Container::DeleteType dt =
  5127.                     Container::DefDelete );
  5128.  
  5129.                     Flushes (empties) the priority queue. The fate of the
  5130.                     removes objects depends on the value of dt as explained
  5131.                     in TShouldDelete::ownsElements.
  5132.  
  5133.                get  Object& get();
  5134.  
  5135.                     Detaches the smallest object from the priority queue
  5136.                     and returns it. The detached object is not itself
  5137.                     destroyed.
  5138.  
  5139. getItemsInContainer countType getItemsInContainer() const ;
  5140.  
  5141.                     Returns the number of items in the priority queue.
  5142.  
  5143.          hashValue  virtual hashValueType hashValue() const;
  5144.  
  5145.                     Returns the hash value of the priority queue. See
  5146.                     HashTable::hashValue for more details.
  5147.  
  5148.          hasMember  int hasMember( const Object& obj ) const;
  5149.  
  5150.                     Returns 1 if obj belongs to the priority queue,
  5151.                     otherwise returns 0.
  5152.  
  5153.       initIterator  virtual void ContainerIterator& initIterator() const;
  5154.  
  5155.                     Creates and returns an iterator for this queue.
  5156.  
  5157.                     See also: ContainerIterator
  5158.  
  5159.  
  5160.  
  5161.  
  5162.                                   - 89 -
  5163.  
  5164.  
  5165. PriorityQueue
  5166.  
  5167.  
  5168.  
  5169.                isA  virtual classType isA() const;
  5170.  
  5171.                     Returns priorityQueueClass, the PriorityQueue type ID.
  5172.  
  5173.            isEmpty  int isEmpty();
  5174.  
  5175.                     Returns 1 if the priority queue is empty, otherwise
  5176.                     returns 0.
  5177.  
  5178.             nameOf  virtual char *nameOf() const;
  5179.  
  5180.                     Returns "PriorityQueue", the PriorityQueue type ID
  5181.                     string.
  5182.  
  5183.           peekLeft  Object& peekLeft();
  5184.  
  5185.                     Returns the smallest object in the priority queue
  5186.                     without removing it.
  5187.  
  5188.                put  void put( Object& o );
  5189.  
  5190.                     Add the given object to the priority queue.
  5191.  
  5192.  
  5193.  
  5194. ===========================================================================
  5195. Queue                                                               queue.h
  5196. ===========================================================================
  5197.  
  5198.                     ┌────────┐  ╔════════════╗
  5199.                     │ Deque  ├──╢   Queue    ║
  5200.                     └────────┘  ╚════════════╝
  5201.  
  5202.                     The instance class Queue, derived from Deque,
  5203.                     implements the traditional queue data structure. A
  5204.                     queue is a FIFO (first-in-first-out) container where
  5205.                     objects are inserted at the left (head) and removed
  5206.                     from the right (tail). For a detailed discussion of
  5207.                     queues, see Knuth's The Art of Computer Programming,
  5208.                     Volume 1, 2.2.1.
  5209.  
  5210.                     The member functions put and get insert and remove
  5211.                     objects.
  5212.                     Queue is implemented as a restricted-access version of
  5213.                     Deque.
  5214.  
  5215.  
  5216.  
  5217.  
  5218.  
  5219.  
  5220.                                   - 90 -
  5221.  
  5222.  
  5223.                                                                       Queue
  5224.  
  5225.  
  5226.  
  5227.            Example  =======================================================
  5228.  
  5229.             Source   #include <queue.h>
  5230.                      #include <strng.h>
  5231.                      #include <assoc.h>
  5232.  
  5233.                      main()
  5234.                      {
  5235.                          Queue q;
  5236.                          String *s1 = new String("a string");
  5237.                          String *s2 = new String("another string");
  5238.                          Association *a1 = new Association(*s1,*s2);
  5239.  
  5240.                          // Populate the queue
  5241.                          q.put(*s1);
  5242.                          q.put(*s2);
  5243.                          q.put(*a1);
  5244.  
  5245.                          // Print to cout as a Container
  5246.                          cout << "As a container:\n" << q << endl;
  5247.  
  5248.                          // Empty the queue to cout
  5249.                          cout << "As a queue:\n";
  5250.                          while (!q.isEmpty())
  5251.                          {
  5252.                              cout << q << endl;
  5253.                          }
  5254.                          cout << endl;
  5255.  
  5256.                          // Queue should be empty
  5257.                          cout << "Should be empty:\n" << q;
  5258.                      }
  5259.  
  5260.             Output   As a container:
  5261.                      Queue {  Association { a string, another a string }
  5262.                      ,
  5263.                          another string,
  5264.                          a string }
  5265.  
  5266.                      As a queue:
  5267.                      a string
  5268.                      another string
  5269.                       Association { a string, another string }
  5270.  
  5271.                      Should be empty:
  5272.                      Queue {  }
  5273.  
  5274.  
  5275.  
  5276.  
  5277.  
  5278.                                   - 91 -
  5279.  
  5280.  
  5281. Queue
  5282.  
  5283.  
  5284.  
  5285.   Member functions  =======================================================
  5286.  
  5287.  
  5288.                get  Object& get();
  5289.  
  5290.                     Removes the object from the end (tail) of the queue. By
  5291.                     default the removed object will not be destroyed. If
  5292.                     the queue is empty, NOOBJECT is returned. Otherwise the
  5293.                     removed object is returned.
  5294.  
  5295.                     See also:   TShouldDelete class
  5296.  
  5297.                isA  virtual classType isA() const;
  5298.  
  5299.                     Returns queueClass, the Queue type ID.
  5300.  
  5301.                put  void put( Object& o );
  5302.  
  5303.                     Add an object to (the tail of) a queue.
  5304.  
  5305.  
  5306.  
  5307. ===========================================================================
  5308. Set                                                                   set.h
  5309. ===========================================================================
  5310.  
  5311.                     ┌────────────┐  ╔════════════╗  ┌────────────┐
  5312.                     │    Bag     ├──╢    Set     ╟──┤ Dictionary │
  5313.                     └────────────┘  ╚════════════╝  └────────────┘
  5314.  
  5315.                     The instance class Set is a collection that allows only
  5316.                     one instance of any object. This restriction calls for
  5317.                     a specialized add member function to trap any
  5318.                     duplicates. Apart from this difference, the Set and Bag
  5319.                     classes are essentially the same.
  5320.  
  5321.  
  5322.   Member functions  =======================================================
  5323.  
  5324.  
  5325.                add  virtual void add( Object& objectToAdd );
  5326.  
  5327.                     Adds the given object to the set only if it is not
  5328.                     already a member. If objectToAdd is found in the set,
  5329.                     add does nothing.
  5330.  
  5331.  
  5332.  
  5333.  
  5334.  
  5335.  
  5336.                                   - 92 -
  5337.  
  5338.  
  5339.                                                                         Set
  5340.  
  5341.  
  5342.  
  5343.                     See also: Collection::hasMember
  5344.  
  5345.        constructor  Set( sizeType setSize = DEFAULT_SET_SIZE );
  5346.  
  5347.                     Creates a set with the given size by calling the base
  5348.                     Bag constructor.
  5349.  
  5350.                     See also:   Bag::Bag
  5351.  
  5352.                isA  virtual classType isA() const;
  5353.  
  5354.                     Returns setClass, the Set class ID.
  5355.  
  5356.             nameOf  virtual char *nameOf() const;
  5357.  
  5358.                     Returns "Set", the Set class ID string.
  5359.  
  5360.  
  5361.  
  5362. ===========================================================================
  5363. Sortable                                                         sortable.h
  5364. ===========================================================================
  5365.  
  5366.                                                      ┌────────────┐
  5367.                                                    ┌─┤   String   │
  5368.                                                    │ └────────────┘
  5369.                     ┌────────────┐  ╔════════════╗ │ ┌────────────┐
  5370.                     │   Object   ├──╢  Sortable  ╟─┼─┤  BaseDate  │
  5371.                     └────────────┘  ╚════════════╝ │ └────────────┘
  5372.                                                    │ ┌────────────┐
  5373.                                                    └─┤  BaseTime  │
  5374.                                                      └────────────┘
  5375.  
  5376.                     Sortable is an abstract class derived from Object. You
  5377.                     can use it to build classes of sortable objects.
  5378.                     Objects are said to be sortable when they can be placed
  5379.                     in an order based on some useful and consistent
  5380.                     definition of "less than", "equal", and "greater than."
  5381.                     Any two of these conditions will suffice, in fact,
  5382.                     since the remaining condition can be constructed with
  5383.                     logical operators. Sortable uses the two primitives
  5384.                     "less than" and "equal" via the pure virtual functions
  5385.                     (pure virtual functions) isLessThan and isEqual. Both
  5386.                     of these member functions are applicable only to
  5387.                     objects of the same type (see operators == and < for
  5388.                     more details). The isEqual member function is a pure
  5389.                     virtual function inherited from Object (since unordered
  5390.                     objects also need a test for equality), whereas
  5391.  
  5392.  
  5393.  
  5394.                                   - 93 -
  5395.  
  5396.  
  5397. Sortable
  5398.  
  5399.  
  5400.  
  5401.                     isLessThan is a new pure virtual function for Sortable.
  5402.                     Your derived classes must define these two member
  5403.                     functions to provide an appropriate ordering of their
  5404.                     objects.
  5405.  
  5406.                     Once isLessThan and isEqual are defined, you can use
  5407.                     the overloaded operators  ==, !=, <, <=, >, >= in the
  5408.                     obvious way (see Related Functions section below). The
  5409.                     < operator tests the objects' types first with isA and
  5410.                     returns 0 if the objects are of different types. Then
  5411.                     if the objects are of the same type, the isLessThan
  5412.                     member is called, returning 0 or 1. If your application
  5413.                     calls for the ordering of objects of different types,
  5414.                     you would have to define your own comparison operators.
  5415.  
  5416.                     The elements stored in ordered containers must clearly
  5417.                     be sortable. For example, when adding elements to a
  5418.                     SortedArray object, the add member function must
  5419.                     compare the "size" of the incoming object against that
  5420.                     of the existing elements. Similarly, Btree objects make
  5421.                     use of magnitude for storage and access methods. Note,
  5422.                     however, that an unordered container can hold either
  5423.                     unsortable or sortable objects.
  5424.  
  5425.                     The type of sortable objects available differs between
  5426.                     the Object-based containers and the template-based
  5427.                     containers. In the Object-based hierarchy you must use
  5428.                     objects ultimately derived from Sortable, whereas the
  5429.                     template containers let you store any object or
  5430.                     predefined data type for which == and < is defined. If
  5431.                     you want to store ints in an Object-based container,
  5432.                     for example, you must invent a suitable class:
  5433.  
  5434.                      class Integer : public Sortable
  5435.                      {
  5436.                         int data;
  5437.                         ...
  5438.                      public:
  5439.  
  5440.                         virtual char *nameOf() const { return "Integer"; }
  5441.                         virtual classType isA() const { return
  5442.                      integerClass; }
  5443.                         virtual int isLessThan( const Object& i ) const
  5444.                                 { return data < ((Integer&)i).data; }
  5445.                         ...
  5446.                      }
  5447.  
  5448.  
  5449.  
  5450.  
  5451.  
  5452.                                   - 94 -
  5453.  
  5454.  
  5455.                                                                    Sortable
  5456.  
  5457.  
  5458.  
  5459.                     The Object-based container library already provides
  5460.                     three useful instance classes derived from Sortable:
  5461.                     String, Date, and Time with the natural ordering you
  5462.                     would expect. Remember, though, that you are free to
  5463.                     define your own orderings in derived classes to suit
  5464.                     your application. You must make sure that your
  5465.                     comparisons are logically consistent. For instance, >
  5466.                     must be transitive: A > B and B > C must imply A > C.
  5467.  
  5468.  
  5469.   Member functions  =======================================================
  5470.  
  5471.  
  5472.          hashValue  virtual hashValueType hashValue() const = 0;
  5473.  
  5474.                     A pure virtual function to be defined by derived
  5475.                     classes to return the hash value of a sortable object.
  5476.                     See HashTable::hashValue for more details.
  5477.  
  5478.                isA  virtual classType isA() const = 0;
  5479.  
  5480.                     Pure virtual function to be defined in derived classes
  5481.                     to return their class ID.
  5482.  
  5483.            isEqual  virtual int isEqual( const Object& testObject ) const =
  5484.                     0;
  5485.  
  5486.                     Pure virtual function to be defined in derived classes
  5487.                     to test for equality. Equality means that the calling
  5488.                     object is the same type as testObject and that their
  5489.                     values (as defined by this member function) are equal.
  5490.                     Returns 1 for equality, otherwise 0.
  5491.  
  5492.         isLessThan  virtual int isLessThan( const Object& testObject )
  5493.                     const = 0;
  5494.  
  5495.                     Pure virtual function to be defined in derived classes
  5496.                     to test for "less than." Returns 1 for "less than",
  5497.                     otherwise 0.
  5498.  
  5499.         isSortable  virtual int isSortable() const;
  5500.  
  5501.                     Returns 1 for all objects derived from Sortable
  5502.                     (overrides Object::isSortable).
  5503.  
  5504.             nameOf  virtual char *nameOf() const = 0;
  5505.  
  5506.  
  5507.  
  5508.  
  5509.  
  5510.                                   - 95 -
  5511.  
  5512.  
  5513. Sortable
  5514.  
  5515.  
  5516.  
  5517.                     Pure virtual function to be defined by derived classes
  5518.                     to return their object ID string.
  5519.  
  5520.            printOn  virtual void printOn( ostream& outputStream ) const =
  5521.                     0;
  5522.  
  5523.   operator << is a  Pure virtual function to be defined in derived classes
  5524.  friend of Object.  to output the object on the given stream. printOn is
  5525.       See page 87.  for internal use by the overloaded operator <<.
  5526.  
  5527.  
  5528.  Related functions  =======================================================
  5529.  
  5530.                     The following overloaded operators are related to
  5531.                     Sortable but are not member functions:
  5532.  
  5533.         operator <  int operator <( const Sortable& test1, const Sortable&
  5534.                     test2 );
  5535.  
  5536.                     Returns 1 if the two objects are of the same type X,
  5537.                     and test1 is "less than" test2 (as defined by
  5538.                     X::isLessThan). Otherwise returns 0.
  5539.  
  5540.                     See also: Sortable::isLessThan, Sortable::isA
  5541.  
  5542.        operator <=  int operator <=( const Sortable& test1, const Sortable&
  5543.                     test2 );
  5544.  
  5545.                     As for operator <, but also tests true for equality.
  5546.  
  5547.         operator >  int operator >( const Sortable& test1, const Sortable&
  5548.                     test2 );
  5549.  
  5550.                     Returns 1 if the two objects are of the same type X,
  5551.                     and test1 is not "less than" and not "equal" to test2
  5552.                     (as defined by X::isLessThan and X::isEqual). Otherwise
  5553.                     returns 0.
  5554.  
  5555.        operator >=  int operator >=( const Sortable& test1, const Sortable&
  5556.                     test2 );
  5557.  
  5558.                     As for operator >, but also tests true for equality.
  5559.                     Note that >= returns !( test1<( test2) ), so it returns
  5560.                     1 if test1 and test2 are of different types.
  5561.  
  5562.  
  5563.  
  5564.  
  5565.  
  5566.  
  5567.  
  5568.                                   - 96 -
  5569.  
  5570.  
  5571.                                                                 SortedArray
  5572.  
  5573.  
  5574.  
  5575. ===========================================================================
  5576. SortedArray                                                      sortarry.h
  5577. ===========================================================================
  5578.  
  5579.                     ┌─────────────┐  ╔════════════╗
  5580.                     │AbstractArray├──╢SortedArray ║
  5581.                     └─────────────┘  ╚════════════╝
  5582.  
  5583.                     The instance class SortedArray, derived from
  5584.                     AbstractArray, defines an array that maintains its
  5585.                     elements in ascending order (according to the ordering
  5586.                     defined for the elements). That is, the element at
  5587.                     index n is less than or equal to the element at index n
  5588.                     + 1. Note that the operator <=, used when adding new
  5589.                     elements to the array, must be defined for comparing
  5590.                     any objects in the array. This will be the case for
  5591.                     objects ultimately derived from Sortable (see the
  5592.                     Related Functions section of the Sortable class
  5593.                     reference) as well as for the standard C integral
  5594.                     types.
  5595.  
  5596.                     Array and SortedArray are identical in many areas (they
  5597.                     have the same base, AbstractArray). One difference is
  5598.                     that SortedArray::detach "squeezes" the array to
  5599.                     maintain ascending order, while Array::detach leaves
  5600.                     "holes" in the array.
  5601.  
  5602.  
  5603.  
  5604. ===========================================================================
  5605. Stack                                                               stack.h
  5606. ===========================================================================
  5607.  
  5608.                     ┌────────────┐  ╔════════════╗
  5609.                     │ Container  ├──╢   Stack    ║
  5610.                     └────────────┘  ╚════════════╝
  5611.  
  5612.  
  5613.                     The instance class Stack, derived from Container, is
  5614.                     one of the sequence classes like Queue and Deque. A
  5615.                     stack is a LIFO (last-in-first-out) linear list for
  5616.                     which all insertions (pushes) and removals (pops) take
  5617.                     place at one end (the top or head) of the list (see D.
  5618.                     E Knuth's The Art of Computer Programming, Volume 1,
  5619.                     2.2). In addition to the traditional pop and push
  5620.                     member functions, Stack provides top, a member function
  5621.                     for examining the object at the top of the stack
  5622.                     without affecting the stack's contents. top must be
  5623.  
  5624.  
  5625.  
  5626.                                   - 97 -
  5627.  
  5628.  
  5629. Stack
  5630.  
  5631.  
  5632.  
  5633.                     used with care since it returns a reference to an
  5634.                     object that may be owned by the stack. Destroying the
  5635.                     object returned by top can disrupt the internal
  5636.                     mechanism for storing the stack. The correct way to
  5637.                     dispose of the top element is to use pop followed by
  5638.                     delete. Stack is implemented internally as a List via a
  5639.                     private data member theStack of type List.
  5640.  
  5641.                     See also: Stacks templates and classes
  5642.  
  5643.  
  5644.            Example  =======================================================
  5645.  
  5646.             Source   #include <stack.h>
  5647.                      #include <strng.h>
  5648.                      #include <assoc.h>
  5649.  
  5650.                      main()
  5651.                      {
  5652.                          Stack s;
  5653.                          String *s1 = new String("a string");
  5654.                          String *s2 = new String("another string");
  5655.                          Association *a1 = new Association(*s1,*s2);
  5656.  
  5657.                          s.push(*s1);
  5658.                          s.push(*s2);
  5659.                          s.push(*a1);
  5660.  
  5661.                          // Print the Stack
  5662.                          cout << "As a Container:\n" << s << endl;
  5663.  
  5664.                          // Empty the stack to cout
  5665.                          cout << "As a Stack:\n";
  5666.                          while (!s.isEmpty())
  5667.                          {
  5668.                              Object& obj = s.pop();
  5669.                              cout << obj << endl;
  5670.                              delete &obj;
  5671.                          }
  5672.                      }
  5673.  
  5674.             Output   As a Container:
  5675.                      Stack {  Association { a string, another string }
  5676.                      ,
  5677.                          another string,
  5678.                          a string }
  5679.  
  5680.                      As a Stack:
  5681.  
  5682.  
  5683.  
  5684.                                   - 98 -
  5685.  
  5686.  
  5687.                                                                       Stack
  5688.  
  5689.  
  5690.  
  5691.                       Association { a string, another string }
  5692.  
  5693.                      another string
  5694.                      a string
  5695.  
  5696.  
  5697.   Member functions  =======================================================
  5698.  
  5699.  
  5700.              flush  virtual void flush( DeleteType dt = DefDelete );
  5701.  
  5702.                     Flushes (empties) the stack. The fate of the removed
  5703.                     objects depends on the argument dt. See TShouldDelete
  5704.                     for details.
  5705.  
  5706. getItemsInContainer virtual countType getItemsInContainer() const;
  5707.  
  5708.                     Returns the number of items in the stack.
  5709.  
  5710.       initIterator  virtual ContainerIterator& initIterator() const;
  5711.  
  5712.                     Creates and returns a stack iterator for the stack.
  5713.  
  5714.                     See also: ContainerIterator class
  5715.  
  5716.                isA  virtual classType isA() const;
  5717.  
  5718.                     Returns stackClass, the Stack type ID.
  5719.  
  5720.            isEmpty  virtual int isEmpty() const;
  5721.  
  5722.                     Returns 1 if the stack is empty, otherwise returns 0.
  5723.  
  5724.             nameOf  virtual char *nameOf() const;
  5725.  
  5726.                     Returns "Stack", the Stack type ID string.
  5727.  
  5728.                pop  Object& pop();
  5729.  
  5730.                     Removes the object from the top of the stack and
  5731.                     returns the object. The fate of the popped object is
  5732.                     determined by ownership as explained in TShouldDelete.
  5733.  
  5734.               push  void push( Object& toPush );
  5735.  
  5736.                     Adds (pushes) the object toPush to the top of the
  5737.                     stack.
  5738.  
  5739.  
  5740.  
  5741.  
  5742.                                   - 99 -
  5743.  
  5744.  
  5745. Stack
  5746.  
  5747.  
  5748.  
  5749.                top  Object& top();
  5750.  
  5751.                     Returns but does not remove the object at the top of
  5752.                     the stack.
  5753.  
  5754.  
  5755.  
  5756. ===========================================================================
  5757. String                                                              strng.h
  5758. ===========================================================================
  5759.  
  5760.                     ┌────────────┐  ╔════════════╗
  5761.                     │  Sortable  ├──╢   String   ║
  5762.                     └────────────┘  ╚════════════╝
  5763.  
  5764.                     String is an instance class, derived from Sortable, to
  5765.                     implement null-terminated, character strings. String
  5766.                     objects are ordered in the usual lexicographic way
  5767.                     using strcmp from the standard C string.h. Note that
  5768.                     the String class include file is spelled strng.h. See
  5769.                     Sortable for a discussion on ordered classes.
  5770.  
  5771.  
  5772.   Member functions  =======================================================
  5773.  
  5774.  
  5775.        constructor  String( const char *aPtr = "" );
  5776.  
  5777.                     Constructs a String object from the given C string.
  5778.  
  5779.        constructor  String(const String& sourceString );
  5780.  
  5781.                     Copy constructor.
  5782.  
  5783.          hashValue  virtual hashValueType hashValue() const;
  5784.  
  5785.                     Returns the hash value of this string. See
  5786.                     HashTable::hashValue for more details.
  5787.  
  5788.                isA  virtual classType isA() const;
  5789.  
  5790.                     Returns stringClass, the Stack type ID.
  5791.  
  5792.            isEqual  virtual int isEqual( const Object& testString ) const;
  5793.  
  5794.                     Returns 1 if the calling string is equal to testString,
  5795.                     otherwise returns 0. You can also use the overloaded
  5796.  
  5797.  
  5798.  
  5799.  
  5800.                                   - 100 -
  5801.  
  5802.  
  5803.                                                                      String
  5804.  
  5805.  
  5806.  
  5807.                     operators == and != as explained in the Related
  5808.                     functions section of the Object class.
  5809.  
  5810.         isLessThan  virtual int isLessThan( const Object& testString )
  5811.                     const;
  5812.  
  5813.                     Returns 1  if the calling string lexically precedes
  5814.                     testString, otherwise returns 0. You can also use the
  5815.                     overloaded operators <, <=, >, and >=, as explained in
  5816.                     the Related functions section of the Storable class.
  5817.  
  5818.  
  5819.             nameOf  virtual char *nameOf() const;
  5820.  
  5821.                     Returns the Stack type ID string.
  5822.  
  5823.            printOn  virtual void printOn( ostream& outputString ) const;
  5824.  
  5825.   operator << is a  Prints this string on the given stream. printOn is
  5826.  friend of Object.  really for internal use by the overloaded operator <<.
  5827.       See page 87.
  5828.         operator =  String& operator =( const String& sourceString );
  5829.  
  5830.                     Overloads the assignment operator for string objects.
  5831.  
  5832.    operator char *  operator const char *() const;
  5833.  
  5834.                     Returns a pointer to this string.
  5835.  
  5836.  
  5837.            Example  =======================================================
  5838.  
  5839.             Source   // File TSTRNG.CPP:    Test the String class
  5840.  
  5841.                      #include <strng.h>
  5842.  
  5843.                      void identify(String&);
  5844.  
  5845.                      main()
  5846.                      {
  5847.                          char s1[21], s2[21];
  5848.  
  5849.                          cout << "Enter a string: ";        // Read a
  5850.                      string
  5851.                          cin >> s1;
  5852.                          String str1(s1);
  5853.                          identify(str1);
  5854.  
  5855.  
  5856.  
  5857.  
  5858.                                   - 101 -
  5859.  
  5860.  
  5861. String
  5862.  
  5863.  
  5864.  
  5865.                          cout << "Enter another string: ";    // Read
  5866.                      another
  5867.                          cin >> s2;
  5868.                          String str2(s2);
  5869.                          identify(str2);
  5870.  
  5871.                          // Do some relational tests:
  5872.                          cout << "Equal: " << str1.isEqual(str2) << endl
  5873.                               << "Less than: " << str1.isLessThan(str2) <<
  5874.                      endl;
  5875.  
  5876.                          // String assignment:
  5877.                          str2 = str1;
  5878.                          cout << "After assignment:\n" << "Equal: "
  5879.                               << str1.isEqual(str2);
  5880.                      }
  5881.  
  5882.                      void identify(String& str)
  5883.                      {
  5884.                          // Echo a String's value and type
  5885.                          cout << "Value: " << str
  5886.                               << ", Object type: " << str.nameOf() << endl
  5887.                      << endl;
  5888.                      }
  5889.  
  5890.             Output   Enter a string: hello
  5891.                      Value: hello, Object type: String
  5892.  
  5893.                      Enter another string: goodbye
  5894.                      Value: goodbye, Object type: String
  5895.  
  5896.                      Equal: 0
  5897.                      Less than: 0
  5898.                      After assignment:
  5899.                      Equal: 1
  5900.  
  5901.  
  5902.  
  5903. ===========================================================================
  5904. Time                                                                ltime.h
  5905. ===========================================================================
  5906.  
  5907.                     ┌────────────┐  ╔════════════╗
  5908.                     │  BaseTime  ├──╢    Time    ║
  5909.                     └────────────┘  ╚════════════╝
  5910.  
  5911.                     Time is a sortable instance class derived from
  5912.                     BaseTime. Time adds a printOn member. You can override
  5913.  
  5914.  
  5915.  
  5916.                                   - 102 -
  5917.  
  5918.  
  5919.                                                                        Time
  5920.  
  5921.  
  5922.  
  5923.                     this in derived classes to cope with international
  5924.                     formatting variations.
  5925.  
  5926.  
  5927.   Member functions  =======================================================
  5928.  
  5929.  
  5930.        constructor  Time();
  5931.  
  5932.                     Calls the BaseTime constructor to create a Time object
  5933.                     with the current time.
  5934.  
  5935.                     See also: BaseTime constructor
  5936.  
  5937.        constructor  Time( const Time& T );
  5938.  
  5939.                     Copy constructor.
  5940.  
  5941.        constructor  Time( unsigned char H, unsigned char M = 0, unsigned
  5942.                           char S = 0, unsigned char D = 0 );
  5943.  
  5944.                     Creates a Time object with the given hour, minutes,
  5945.                     seconds, and hundredths of seconds.
  5946.  
  5947.                isA  virtual classType isA() const;
  5948.  
  5949.                     Returns timeClass, the Time class ID.
  5950.  
  5951.             nameOf  virtual char *nameOf() const;
  5952.  
  5953.                     Returns "Time", the Time class ID string.
  5954.  
  5955.            printOn  virtual void printOn( ostream& outputStream ) const;
  5956.  
  5957.   operator << is a  Sends a formatted Time object to the given output
  5958.  friend of Object.  stream. The default format is hh:mm:ss:dd a/pm with
  5959.       See page 87.  nonmilitary hours. printOn is for internal use by the
  5960.                     overloaded operator <<.
  5961.  
  5962.  
  5963.  
  5964.  
  5965.  
  5966.  
  5967.  
  5968.  
  5969.  
  5970.  
  5971.  
  5972.  
  5973.  
  5974.                                   - 103 -
  5975.  
  5976.  
  5977. Timer
  5978.  
  5979.  
  5980.  
  5981. ===========================================================================
  5982. Timer                                                               timer.h
  5983. ===========================================================================
  5984.  
  5985.                     ╔════════════╗
  5986.                     ║   Timer    ╟
  5987.                     ╚════════════╝
  5988.  
  5989.                     Timer is an instance class implementing a stop watch.
  5990.                     You can use Timer objects to time program execution by
  5991.                     calling the member functions start and stop within your
  5992.                     program, and then using time to return the elapsed
  5993.                     time. The reset member function resets the elapsed time
  5994.                     to zero. Successive starts and stops will accumulate
  5995.                     elapsed time until a reset.
  5996.  
  5997.  
  5998.   Member functions  =======================================================
  5999.  
  6000.  
  6001.        constructor  Timer();
  6002.  
  6003.                     Creates a Timer object.
  6004.  
  6005.              reset  void reset();
  6006.  
  6007.                     Clears the elapsed time accumulated from previous
  6008.                     start/stop sequences.
  6009.  
  6010.         resolution  static double resolution();
  6011.  
  6012.                     Determines the timer resolution for all timer objects.
  6013.                     This value is hardware and OS dependent. For example:
  6014.  
  6015.                         if( elapsedTime < timer.resolution() )
  6016.                            cout << "Measured time not meaningful." << endl;
  6017.  
  6018.              start  void start();
  6019.  
  6020.                     Ignored if the timer is running, otherwise starts the
  6021.                     timer. The elapsed times from any previous start/stop
  6022.                     sequences are accumulated until reset is called.
  6023.  
  6024.             status  int status();
  6025.  
  6026.                     Returns 1 if the timer is running, otherwise 0.
  6027.  
  6028.               stop  void stop();
  6029.  
  6030.  
  6031.  
  6032.                                   - 104 -
  6033.  
  6034.  
  6035.                                                                       Timer
  6036.  
  6037.  
  6038.  
  6039.                     Stops the timer. The accumulated elapsed time is
  6040.                     preserved until a reset call.
  6041.  
  6042.               time  double time();
  6043.  
  6044.                     Returns the elapsed time. The precision is given by the
  6045.                     value returned by the member function resolution.
  6046.  
  6047.  
  6048.  
  6049. ===========================================================================
  6050. TShouldDelete                                                      shddel.h
  6051. ===========================================================================
  6052.  
  6053. Figure 3: Class hierarchies in CLASSLIB
  6054.  
  6055.  
  6056.     TShouldDelete───────┬──Association
  6057.                         └──Container
  6058.  
  6059.                     TShouldDelete maintains the ownership state of a
  6060.                     container. The fate of objects that are removed from a
  6061.                     container can be made to depend on whether the
  6062.                     container owns its elements or not. Similarly, when a
  6063.                     container is destroyed, ownership can dictate the fate
  6064.                     of contained objects that are still in scope. As a
  6065.                     virtual base class for Container and Association,
  6066.                     TShouldDelete provides ownership control for all
  6067.                     containers and associations. The member function
  6068.                     ownsElements can be used either to report or to change
  6069.                     the ownership status of a container. delObj is used to
  6070.                     determine if objects in containers or associations
  6071.                     should be deleted or not.
  6072.  
  6073.  
  6074.   Member functions  =======================================================
  6075.  
  6076.  
  6077.        constructor  TShouldDelete( DeleteType dt = Delete );
  6078.  
  6079.                     Creates a TShouldDelete object. By default, containers
  6080.                     and associations own their elements. DeleteType is an
  6081.                     enumeration declared within the class as follows:
  6082.  
  6083.                     enum DeleteType { NoDelete, DefDelete, Delete };
  6084.  
  6085.       ownsElements  int ownsElements();
  6086.                     void ownsElements( int del );
  6087.  
  6088.  
  6089.  
  6090.                                   - 105 -
  6091.  
  6092.  
  6093. TShouldDelete
  6094.  
  6095.  
  6096.  
  6097.                     The first form returns 1 if the container owns its
  6098.                     elements, otherwise it returns 0. The second form
  6099.                     changes the ownership status as follows: if del is 0,
  6100.                     ownership is turned off; otherwise ownership is turned
  6101.                     on.
  6102.  
  6103.             delObj  int delObj( DeleteType dt );
  6104.  
  6105.                     Tests the state of ownership and returns 1 if the
  6106.                     contained objects should be deleted or 0 if the
  6107.                     contained elements should not be deleted. The factors
  6108.                     determining this are (i) the current ownership state
  6109.                     and (ii) the value of dt, as shown in the following
  6110.                     table.
  6111.                     delObj returns 1 if (dt is Delete) or (dt is DefDelete
  6112.                     and the container currently owns its elements). Thus a
  6113.                     dt of NoDelete returns 0 (don't delete) regardless of
  6114.                     ownership; a dt of Delete return 1 (do delete)
  6115.                     regardless of ownership; and a dt of DefDelete returns
  6116.                     1 (do delete) if the elements are owned, but a 0 (don't
  6117.                     delete) if the objects are not owned.
  6118.  
  6119.  
  6120.                     -------------------------------------------------------
  6121.                                       delObj
  6122.                       ownsElements  no    yes
  6123.                     -------------------------------------------------------
  6124.  
  6125.                       NoDelete      no    no
  6126.                       DefDelete     no    yes
  6127.                       Delete        yes   yes
  6128.  
  6129.                     -------------------------------------------------------
  6130.  
  6131.  
  6132.  
  6133.  
  6134.  
  6135.  
  6136.  
  6137.  
  6138.  
  6139.  
  6140.  
  6141.  
  6142.  
  6143.  
  6144.  
  6145.  
  6146.  
  6147.  
  6148.                                   - 106 -
  6149.  
  6150.  
  6151.  
  6152.  
  6153.  
  6154.  
  6155. INDEX
  6156. ___________________________________________________________________________
  6157.  
  6158.  
  6159.  
  6160.  
  6161.  
  6162. A                                      B
  6163. abbreviations                          Bag class 47
  6164.   CLASSLIB names and 19                BaseDate class 49
  6165. abstract classes 4                     BaseTime class 51
  6166. abstract data types                    BI_ prefix
  6167.   BIDS class names 19                    class names 19
  6168.   class library and 13                 BIDS template library 13
  6169. AbstractArray class 37                 Borland International Data
  6170. add                                      Structures (BIDS) 13
  6171.   Array member function 42             Btree class 53
  6172.   Bag member function 47               BtreeIterator class 55
  6173.   Btree member function 53
  6174.   Collection member function 58
  6175.   Dictionary member function 69        C
  6176.   DoubleList member function 71        C prefix
  6177.   HashTable member function 76           class names 19
  6178.   List member function 79              CHECK macro 35
  6179.   Sets member function 92              class templates 17
  6180. addAt                                  classes
  6181.   Array member function 42               abstract vs instance 4
  6182. addAtHead                                arrays
  6183.   DoubleList member function 71            sorted 97
  6184. addAtTail                                collections 12
  6185.   DoubleList member function 71          date and time 65, 102
  6186. ADT                                      debugging modes 35
  6187.   header files 22                        hierarchies 4
  6188. ADT (abstract data types) 13               object-based 6
  6189. Array class 41                             traversing 43
  6190. ArrayInterator                           lists 70
  6191.   AbstractArray friend 40                priority queues 88
  6192. ArrayIterator class 43                   queue 90
  6193. arrays                                   queues
  6194.   classes for 37, 41                       double-ended 66
  6195.   classes for sorted 97                  sequence 12, 66, 90, 97
  6196. arraySize                                  rules for 12
  6197.   AbstractArray member function 38       sortable objects 93
  6198. ascending sort 97                        stack 97
  6199. assertion macros 35                      string 100
  6200. Association class 7, 44                CLASSLIB naming conventions 19
  6201.   example program 34                   Collection class 12, 57
  6202.  
  6203.  
  6204.  
  6205.  
  6206. Index                                                                   107
  6207.  
  6208.  
  6209.  
  6210.  
  6211.  
  6212.  
  6213. collections                              reference section 36
  6214.   ordered 13                           container classes 6, 8, 59
  6215.   random access to 37                    functions of 59
  6216.   unordered 13                         container hierarchy
  6217.     Bag class 47                         object-based 4
  6218.     Dictionary class 69                ContainerIterator class 64
  6219.     DoubleList class 70                  containers and 64
  6220.     HashTable class 75                   hierarchy 11
  6221.     List class 79                      containers
  6222.     Set class 92                         basics 4
  6223. condFuncType definition 84               ContainerIterator class and 64
  6224. constructors                             direct 19
  6225.   AbstractArray member function 38       elements of 59
  6226.   Array member function 42               equality testing 60
  6227.   ArrayIterator member function 43       flushing 10, 59
  6228.   Association member function 44         implementation 14
  6229.   Bag member function 47                 indirect 19
  6230.   Basedate member function 49          current
  6231.   Basetime member function 51            ArrayIterator member function 43
  6232.   Btree member function 53               BtreeIterator member function 56
  6233.   BtreeIterator member function 56       ContainerIterator member function
  6234.   Collection member function 58          64
  6235.   Container member function 60           DoubleListIterator member
  6236.   Date member function 65                function 73
  6237.   Dictionary member function 70          HashTableIterator member function
  6238.   DoubleList member function 71          78
  6239.   DoubleListIterator member              ListIterator member function 81
  6240.   function 73
  6241.   HashTable member function 76
  6242.   HashTableIterator member function    D
  6243.   78                                   Date class 65
  6244.   List member function 79              dates
  6245.   ListIterator member function 81        class 65
  6246.   Object member function 84            Day
  6247.   Sets member function 93                Basedate member function 49
  6248.   String member function 100           __DEBUG macro 35
  6249.   Time member function 103             decrNofKeys
  6250.   Timer member function 104              Btree member function 53
  6251.   TShouldDelete member function 105    delete
  6252. container class library                  Error member function 75
  6253.   directories 31                       delObj
  6254.     examples 34                          TShouldDelete member function 106
  6255.     INCLUDE 32                         delta
  6256.     lib 34                               AbstractArray data member 37
  6257.     source 32                          Deque class 66
  6258.   example programs 34                  destroy
  6259.   memory models and 32                   AbstractArray member function 38
  6260.   project files and 32                   Collection member function 58
  6261.  
  6262.  
  6263.  
  6264.                                   - 108 -
  6265.  
  6266.  
  6267.  
  6268.  
  6269.  
  6270.  
  6271. destroyFromHead                          HashTable member function 77
  6272.   DoubleList member function 71        firstThat
  6273. destroyFromTail                          Bag member function 47
  6274.   DoubleList member function 71          Container member function 60
  6275. detach                                   Object member function 84
  6276.   AbstractArray member function 38     flush
  6277.   Bag member function 47                 Bag member function 47
  6278.   Btree member function 53               Btree member function 54
  6279.   Collection member function 58          Container member function 61
  6280.   DoubleList member function 71          Deque member function 68
  6281.   HashTable member function 76           DoubleList member function 72
  6282.   List member function 79                HashTable member function 77
  6283.   SortedArray member function 97         List member function 80
  6284. detachFromHead                           PriorityQueue member function 89
  6285.   DoubleList member function 71          Stacks member function 99
  6286. detachFromTail                         forEach
  6287.   DoubleList member function 71          Bag member function 48
  6288. detachLeft                               Container member function 61
  6289.   PriorityQueue member function 89       Object member function 85
  6290. Dictionary class 69                    free
  6291.   example program 34                     MemBlocks member function 83
  6292. direct and indirect data structures    fundamental data structure
  6293.   14                                     class templates 17
  6294. directories                            fundamental data structures
  6295.   container class library 31             class library and 13
  6296. DIRECTRY (container class library        Object-based classes 20
  6297.   example program) 34
  6298. DoubleList class 70
  6299. DoubleListIterator class 73            G
  6300.                                        get
  6301.                                          PriorityQueue member function 89
  6302. E                                        Queue member function 92
  6303. elements                               getItemsInContainer
  6304.   ordering definition 19                 Bag member function 48
  6305. Error class 7, 74                        Container member function 61
  6306. examples directory                       Deques member function 68
  6307.   container class library 34             PriorityQueue member function 89
  6308.                                          Stacks member function 99
  6309.                                        getLeft
  6310. F                                        Deque member function 68
  6311. FDS                                    getRight
  6312.   header files 22                        Deque member function 68
  6313. FDS (fundamental data structures)
  6314.   13
  6315. findmember                             H
  6316.   Bag member function 47               hash table
  6317.   Btree member function 54               iterators 78
  6318.   Collection member function 58        HashTable class 75
  6319.  
  6320.  
  6321.  
  6322. Index                                                                   109
  6323.  
  6324.  
  6325.  
  6326.  
  6327.  
  6328.  
  6329. HashTableIterator class 78             instance classes 4
  6330. hashValue                              isA
  6331.   Association member function 44         Array member function 43
  6332.   Basedate member function 49            Association member function 44
  6333.   Basetime member function 51            Bag member function 48
  6334.   Btree member function 54               Basedate member function 50
  6335.   Container member function 61           Basetime member function 52
  6336.   HashTable member function 77           Btree member function 54
  6337.   List member function 80                Container member function 62
  6338.   Object member function 85              Date member function 66
  6339.   PriorityQueue member function 89       Deque member function 68
  6340.   Sortable member function 95            Dictionary member function 70
  6341.   String member function 100             DoubleList member function 72
  6342. hasMember                                Error member function 75
  6343.   Bag member function 48                 HashTable member function 78
  6344.   Btree member function 54               List member function 80
  6345.   Collection member function 59          Object member function 85
  6346.   PriorityQueue member function 89       PriorityQueue member function 89
  6347. hour                                     Queue member function 92
  6348.   Basetime member function 51            Set member function 93
  6349. hundredths                               Sortable member function 95
  6350.   Basetime member function 51            Stack member function 99
  6351.                                          String member function 100
  6352.                                          Time member function 103
  6353. I                                      isAssociation
  6354. i_add                                    Association member function 44
  6355.   Btree member function 54               Object member function 85
  6356. I prefix                               isEmpty
  6357.   class names 19                         Bag member function 48
  6358. Imp suffix                               Container member function 62
  6359.   class names 19                         Deques member function 68
  6360. INCLUDE directory                        PriorityQueue member function 90
  6361.   container class library 32             Stack member function 99
  6362. incrNofKeys                            isEqual
  6363.   Btree member function 54               AbstractArray member function 39
  6364. initIterator                             Association member function 45
  6365.   AbstractArray member function 39       Basedate member function 50
  6366.   Bag member function 48                 Basetime member function 52
  6367.   Btree member function 54               Btree member function 54
  6368.   Container member function 61           Container member function 62
  6369.   Deque member function 68               Error member function 75
  6370.   DoubleList member function 72          Object member function 86
  6371.   HashTable member function 77           Sortable member function 95
  6372.   List member function 80                String member function 100
  6373.   PriorityQueue member function 89     isLessThan
  6374.   Stacks member function 99              Basedate member function 50
  6375. InnerNode                                Basetime member function 52
  6376.   Btree friend class 53                  Sortable member function 95
  6377.  
  6378.  
  6379.  
  6380.                                   - 110 -
  6381.  
  6382.  
  6383.  
  6384.  
  6385.  
  6386.  
  6387.   String member function 101           M
  6388. isSortable                             member functions
  6389.   Object member function 86              virtual
  6390.   Sortable member function 95              pure 4
  6391. Item                                   MemBlocks class 82
  6392.   Btree friend class 53                memory models
  6393. itemsInContainer                         container class library and 32
  6394.   Container data member 60             MemStack class 83
  6395. iterators                              minute
  6396.   DoubleList 73                          Basetime member function 52
  6397.   internal and external 11             Month
  6398. iterFuncType definition 61               Basedate member function 50
  6399.  
  6400.  
  6401. K                                      N
  6402. key                                    nameOf
  6403.   Association class 44                   Arrays member function 43
  6404.   Association member function 45         Association member function 45
  6405.                                          Bag member function 49
  6406.                                          Basedate member function 50
  6407. L                                        Basetime member function 52
  6408. Last-In-First-Out (LIFO) 14              Btree member function 54
  6409. lastElementIndex                         Container member function 62
  6410.   AbstractArray data member 37           Date member function 66
  6411. lastThat                                 Deque member function 68
  6412.   Bag member function 48                 Dictionary member function 70
  6413.   Container member function 62           DoubleList member function 72
  6414.   Object member function 86              Error member function 75
  6415. LeafNode                                 HashTable member function 78
  6416.   Btree friend class 53                  List member function 80
  6417. lib directory                            Object member function 86
  6418.   container class library 34             PriorityQueue member function 90
  6419. List class 79                            Set member function 93
  6420.   iterators 81                           Sortable member function 95
  6421. ListElement class 79                     Stacks member function 99
  6422. ListIterator class 81                    String member function 101
  6423. lists                                    Time member function 103
  6424.   classes for 70                       new
  6425.   linked                                 Object member function 86
  6426.     traversing 81                      Node
  6427. lookup                                   Btree friend 55
  6428.   Dictionary member function 70          Btree friend class 53
  6429. LOOKUP (container class library        non-container classes 6
  6430.   example program) 34
  6431. lowerBound
  6432.   AbstractArray member function 39     O
  6433. lowerbound                             O prefix 21
  6434.   AbstractArray data member 37           class names 19
  6435.  
  6436.  
  6437.  
  6438. Index                                                                   111
  6439.  
  6440.  
  6441.  
  6442.  
  6443.  
  6444.  
  6445. Object class 4, 84                     operator char *
  6446. Object container class library           String member function 101
  6447.   version 3.0 changes to 1             operator int
  6448. objectAt                                 ArrayIterator member function 43
  6449.   AbstractArray member function 39       BtreeIterator member function 56
  6450. objects                                  ContainerIterator member function
  6451.   automatic 11                           64
  6452.   detaching 10                           DoubleListIterator member
  6453.   heap 11                                function 74
  6454.   in containers                          HashTableIterator member function
  6455.     counting 59                          78
  6456.     displaying 60                        ListIterator member function 81
  6457.     iterating 60                       order
  6458.     ownership 59                         Btree member function 55
  6459.   ownership 9                          ordered collections 7, 13
  6460.   sortable 93                          ownsElements 9
  6461. operator <                               Bag member function 49
  6462.   overloaded 96                          TShouldDelete member function 105
  6463. operator =
  6464.   String member function 101
  6465. operator >                             P
  6466.   overloaded 96                        peekAtHead
  6467. operator !=                              DoubleList member function 72
  6468.   overloaded 88                        peekAtTail
  6469. operator ++                              DoubleList member function 72
  6470.   ArrayIterator member function 43     peekHead
  6471.   BtreeIterator member function 56       List member function 80
  6472.   ContainerIterator member function    peekLeft
  6473.   64                                     Deque member function 69
  6474.   DoubleListIterator member              PriorityQueue member function 90
  6475.   function 73                          peekRight
  6476.   HashTableIterator member function      Deque member function 69
  6477.   79                                   pop
  6478.   ListIterator member function 81        Stacks member function 99
  6479. operator <<                            PRECONDITION macro 35
  6480.   Object friends 87                    printContentsOn
  6481. operator <=                              AbstractArray member function 39
  6482.   overloaded 96                        printHeader
  6483. operator ==                              Container member function 62
  6484.   overloaded 87                        printOn
  6485. operator >=                              Association member function 45
  6486.   overloaded 96                          Basedate member function 50
  6487. operator []                              Basetime member function 52
  6488.   AbstractArray member function 39       Btree member function 55
  6489.   Btree member function 55               Container member function 62
  6490. operator - -                             Date member function 66
  6491.   DoubleListIterator member              Error member function 75
  6492.   function 73                            Object member function 87
  6493.  
  6494.  
  6495.  
  6496.                                   - 112 -
  6497.  
  6498.  
  6499.  
  6500.  
  6501.  
  6502.  
  6503.   Sortable member function 96          restart
  6504.   String member function 101             ArrayIterator member function 44
  6505.   Time member function 103               BtreeIterator member function 56
  6506. printSeparator                           ContainerIterator member function
  6507.   Container member function 63           65
  6508. printTrailer                             DoubleListIterator member
  6509.   Container member function 63           function 74
  6510. priority queues 88                       HashTableIterator member function
  6511. PriorityQueue class 88                   79
  6512. project files                            ListIterator member function 81
  6513.   container class libraries and 32     REVERSE (container class library
  6514. ptrAt                                    example program) 34
  6515.   AbstractArray member function 40
  6516. ptrToRef
  6517.   Object member function 87            S
  6518. push                                   S prefix
  6519.   Stacks member function 99              class names 19
  6520. put                                    second
  6521.   PriorityQueue member function 90       Basetime member function 52
  6522.   Queue member function 92             Set class 92
  6523. putLeft                                setData
  6524.   Deque member function 69               AbstractArray member function 40
  6525. putRight                               SetDay
  6526.   Deque member function 69               Basedate member function 50
  6527.                                        setHour
  6528.                                          Basetime member function 52
  6529. Q                                      setHundredths
  6530. Queue class 90                           Basetime member function 52
  6531.   example program 34                   setMinute
  6532. queues 90                                Basetime member function 52
  6533.   double-ended 66                      SetMonth
  6534. QUEUETST (container class library        Basedate member function 50
  6535.   example program) 34                  setSecond
  6536.                                          Basetime member function 52
  6537.                                        SetYear
  6538. R                                        Basedate member function 50
  6539. rank                                   Sortable class 7, 93
  6540.   Btree member function 55               ordered collections 13
  6541. reallocate                             SortedArray class 97
  6542.   AbstractArray member function 40       example program 34
  6543.   MemBlocks member function 83         sorts
  6544. removeEntry                              ascending 97
  6545.   AbstractArray member function 40     source directory
  6546. reset                                    container class library 32
  6547.   Timer member function 104            squeezeEntry
  6548. resolution                               AbstractArray member function 40
  6549.   Timer member function 104            Stack class 97
  6550.                                          example program 34
  6551.  
  6552.  
  6553.  
  6554. Index                                                                   113
  6555.  
  6556.  
  6557.  
  6558.  
  6559.  
  6560.  
  6561. start                                  top
  6562.   Timer member function 104              Stacks member function 99
  6563. status                                 TShouldDelete class 105
  6564.   Timer member function 104
  6565. stdtempl.h 22
  6566. stop                                   U
  6567.   Timer member function 104            unordered collections 13
  6568. String class 100                         Bag class 47
  6569.   example program 34                     Dictionary class 69
  6570. strings                                  DoubleList class 70
  6571.   classes for 100                        HashTable class 75
  6572. STRNGMAX (container class library        List class 79
  6573.   example program) 34                    Set class 92
  6574.                                        upperBound
  6575.                                          AbstractArray member function 40
  6576. T                                      upperbound
  6577. TC prefix 21                             AbstractArray data member 38
  6578.   class names 19
  6579. template-based container library 13
  6580. TEMPLATES                              V
  6581.   conditional compilation 32           value
  6582. Templates                                Association class 44
  6583.   Arrays example 30                      Association member function 45
  6584.   Deques example 30
  6585. templates
  6586.   approach to class library 3, 15      Y
  6587.   container classes and 14             Year
  6588.   instantiating 19                       Basedate member function 50
  6589. time
  6590.   Timer member function 105
  6591. Time class 102                         Z
  6592.   example program 34                   ZERO
  6593. Timer class 104                          Object data member 84
  6594.  
  6595.  
  6596.  
  6597.  
  6598.  
  6599.  
  6600.  
  6601.  
  6602.  
  6603.  
  6604.  
  6605.  
  6606.  
  6607.  
  6608.  
  6609.  
  6610.  
  6611.  
  6612.                                   - 114 -
  6613.  
  6614.  
  6615.  
  6616.  
  6617.  
  6618.  
  6619. CONTENTS
  6620. ___________________________________________________________________________
  6621.  
  6622.  
  6623.  
  6624.  
  6625.  
  6626. 1  The container class libraries   1     Member functions  . . . . . . . 38
  6627. What's new since version 1.0?  . . 1     Friends . . . . . . . . . . . . 40
  6628. Why two sets of libraries? . . . . 3   Array . . . . . . . . . . . . . . 41
  6629. Container basics . . . . . . . . . 4     Example . . . . . . . . . . . . 41
  6630.     Object-based and other               Member functions  . . . . . . . 42
  6631.     classes  . . . . . . . . . . . 6   ArrayIterator . . . . . . . . . . 43
  6632.   Class categories . . . . . . . . 6     Member functions  . . . . . . . 43
  6633.   Non-container classes  . . . . . 7   Association . . . . . . . . . . . 44
  6634.     Error class  . . . . . . . . . 7     Member functions  . . . . . . . 44
  6635.     Sortable class . . . . . . . . 7     Example . . . . . . . . . . . . 45
  6636.     Association class  . . . . . . 8   Bag . . . . . . . . . . . . . . . 47
  6637.   Container classes  . . . . . . . 8     Member functions  . . . . . . . 47
  6638.   Containers and ownership . . . . 9   BaseDate  . . . . . . . . . . . . 49
  6639.   Container iterators  . . . . .  11     Member functions  . . . . . . . 49
  6640.   Sequence classes . . . . . . .  12   BaseTime  . . . . . . . . . . . . 51
  6641.   Collections  . . . . . . . . .  12     Member functions  . . . . . . . 51
  6642.     Unordered collections  . . .  13   Btree . . . . . . . . . . . . . . 53
  6643.     Ordered collections  . . . .  13     Member functions  . . . . . . . 53
  6644. The BIDS template library  . . .  13     Friends . . . . . . . . . . . . 55
  6645.   Templates, classes, and              BtreeIterator . . . . . . . . . . 55
  6646.   containers . . . . . . . . . .  14     Member functions  . . . . . . . 56
  6647.   Container implementation . . .  14   Collection  . . . . . . . . . . . 57
  6648.   The template solution  . . . .  15     Member functions  . . . . . . . 58
  6649.     ADTs and FDSs  . . . . . . .  16   Container . . . . . . . . . . . . 59
  6650.     Class templates  . . . . . .  17     Member functions  . . . . . . . 60
  6651.   Container class compatibility . 20     Friends . . . . . . . . . . . . 63
  6652.   Header files . . . . . . . . .  22   ContainerIterator . . . . . . . . 64
  6653.   Tuning an application  . . . .  23     Member functions  . . . . . . . 64
  6654.   FDS implementation . . . . . .  24   Date  . . . . . . . . . . . . . . 65
  6655.   ADT implementation . . . . . .  27     Member functions  . . . . . . . 65
  6656. The class library directory  . .  31   Deque . . . . . . . . . . . . . . 66
  6657.   The INCLUDE directory  . . . .  32     Example . . . . . . . . . . . . 67
  6658.   The OBJS directory . . . . . .  32     Member functions  . . . . . . . 68
  6659.   The SOURCE directory . . . . .  32   Dictionary  . . . . . . . . . . . 69
  6660.     Creating a library . . . . .  33     Member functions  . . . . . . . 69
  6661.   The LIB directory  . . . . . .  34   DoubleList  . . . . . . . . . . . 70
  6662.   The EXAMPLES directory . . . .  34     Member functions  . . . . . . . 71
  6663. Preconditions and checks . . . .  35     Friends . . . . . . . . . . . . 73
  6664. Container class reference  . . .  36   DoubleListIterator  . . . . . . . 73
  6665. AbstractArray  . . . . . . . . .  37     Member functions  . . . . . . . 73
  6666.   Data members . . . . . . . . .  37   Error . . . . . . . . . . . . . . 74
  6667.  
  6668.  
  6669.  
  6670.                                      i
  6671.  
  6672.  
  6673.  
  6674.  
  6675.  
  6676.  
  6677.   Member functions . . . . . . .  75     Member functions  . . . . . . . 92
  6678. HashTable  . . . . . . . . . . .  75   Set . . . . . . . . . . . . . . . 92
  6679.   Member functions . . . . . . .  76     Member functions  . . . . . . . 92
  6680.   Friends  . . . . . . . . . . .  78   Sortable  . . . . . . . . . . . . 93
  6681. HashTableIterator  . . . . . . .  78     Member functions  . . . . . . . 95
  6682.   Member functions . . . . . . .  78     Related functions . . . . . . . 96
  6683. List . . . . . . . . . . . . . .  79   SortedArray . . . . . . . . . . . 97
  6684.   Member functions . . . . . . .  79   Stack . . . . . . . . . . . . . . 97
  6685.   Friends  . . . . . . . . . . .  80     Example . . . . . . . . . . . . 98
  6686. ListIterator . . . . . . . . . .  81     Member functions  . . . . . . . 99
  6687.   Member functions . . . . . . .  81   String  . . . . . . . . . . . .  100
  6688. MemBlocks  . . . . . . . . . . .  82     Member functions  . . . . . .  100
  6689. MemStack . . . . . . . . . . . .  83     Example . . . . . . . . . . .  101
  6690. Object . . . . . . . . . . . . .  84   Time  . . . . . . . . . . . . .  102
  6691.   Data member  . . . . . . . . .  84     Member functions  . . . . . .  103
  6692.   Member functions . . . . . . .  84   Timer . . . . . . . . . . . . .  104
  6693.   Friends  . . . . . . . . . . .  87     Member functions  . . . . . .  104
  6694.   Related functions  . . . . . .  87   TShouldDelete . . . . . . . . .  105
  6695. PriorityQueue  . . . . . . . . .  88     Member functions  . . . . . .  105
  6696.   Member functions . . . . . . .  89
  6697. Queue  . . . . . . . . . . . . .  90   Index                            107
  6698.   Example  . . . . . . . . . . .  91
  6699.  
  6700.  
  6701.  
  6702.  
  6703.  
  6704.  
  6705.  
  6706.  
  6707.  
  6708.  
  6709.  
  6710.  
  6711.  
  6712.  
  6713.  
  6714.  
  6715.  
  6716.  
  6717.  
  6718.  
  6719.  
  6720.  
  6721.  
  6722.  
  6723.  
  6724.  
  6725.  
  6726.  
  6727.  
  6728.                                     ii
  6729.  
  6730.  
  6731.  
  6732.  
  6733.  
  6734.  
  6735. TABLES
  6736. ___________________________________________________________________________
  6737.  
  6738.  
  6739.  
  6740.  
  6741.  
  6742. 1: ADTs as fundamental data            4: ADT class templates  . . . . . 19
  6743.    structures  . . . . . . . . . .16   5: Object-based FDS classes . . . 20
  6744. 2: FDS class templates . . . . . .17   6: Class debugging modes  . . . . 35
  6745. 3: Abbreviations in CLASSLIB
  6746.    names . . . . . . . . . . . . .19
  6747.  
  6748.  
  6749.  
  6750.  
  6751.  
  6752.  
  6753.  
  6754.  
  6755.  
  6756.  
  6757.  
  6758.  
  6759.  
  6760.  
  6761.  
  6762.  
  6763.  
  6764.  
  6765.  
  6766.  
  6767.  
  6768.  
  6769.  
  6770.  
  6771.  
  6772.  
  6773.  
  6774.  
  6775.  
  6776.  
  6777.  
  6778.  
  6779.  
  6780.  
  6781.  
  6782.  
  6783.  
  6784.  
  6785.  
  6786.                                     iii
  6787.  
  6788.  
  6789.  
  6790.  
  6791.  
  6792.  
  6793. 1: Class hierarchies in CLASSLIB . 5   3: Class hierarchies in
  6794. 2: TShouldDelete hierarchy . . . .29      CLASSLIB . . . . . . . . . . .105
  6795.  
  6796.  
  6797.  
  6798.  
  6799.  
  6800.  
  6801.  
  6802.  
  6803.  
  6804.  
  6805.  
  6806.  
  6807.  
  6808.  
  6809.  
  6810.  
  6811.  
  6812.  
  6813.  
  6814.  
  6815.  
  6816.  
  6817.  
  6818.  
  6819.  
  6820.  
  6821.  
  6822.  
  6823.  
  6824.  
  6825.  
  6826.  
  6827.  
  6828.  
  6829.  
  6830.  
  6831.  
  6832.  
  6833.  
  6834.  
  6835.  
  6836.  
  6837.  
  6838.  
  6839.  
  6840.  
  6841.  
  6842.  
  6843.  
  6844.                                     iv
  6845.